[Java的] 从输入文件阵列, 排序,并在Java中导出的文件 – 从文件导入阵列, 在Java中排序和导出文件
– 创建 1 一流的网络初始化 (类InitArray)
– 创建 1 文件导入和导出类从类数组初始化数组继承 (类IOArray扩展InitArray)
– 创建 1 类继承排序的数组的数组初始化类 (类SortArray扩展InitArray)
– 级阵列 (排列) 包含的主要功能() 可执行程序
这里是代码:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
class InitArray
{
int [] Element;
}
class IOArray extends InitArray
{
void input_file() throws FileNotFoundException
{
FileInputStream fi = new FileInputStream("input.txt");
Scanner inp = new Scanner(fi,"UTF-8");
String temp = inp.nextLine(); //doc dong mang trong file
inp.close();
String [] item = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
Element = new int[item.length];
for(int i=0; i<item.length; i++) //doi kiem string sang int cua cac phan tu
Element[i] = Integer.parseInt(item[i]);
}
void output_file() throws IOException
{
FileOutputStream fo = new FileOutputStream("output.txt");
PrintWriter out = new PrintWriter(fo);
for (int i=0; i<Element.length; i++)
out.printf("%-5d",Element[i]);
out.close();
}
}
class SortArray extends InitArray
{
public void sort(IOArray A) //phuong thuc sap xep
{
Arrays.sort(A.Element);
}
}
class Array
{
public static void main(String[] args) throws IOException
{
IOArray Arr = new IOArray();
Arr.input_file(); //nhap tu file
SortArray SArr = new SortArray();
SArr.sort(Arr); //sap xep
Arr.output_file(); //xuat ra file
System.out.println("nSucces ! Open file output.txt to view");
}
}



有人问我如何扩展类类SortArray InitArray?
啊,所以我可以真的只使用数组, 还有没有必要继承.
我喜欢这一事实, :在
ALO町MK心面MK海chut DKķ
你通过与我聊天什么: fb.com/nguyenvanquan7826