如何将file方法内的二维数组改为一维数组 并且 返回这个一维数组  存入到主方法内的Number数组
import java.util.*;
import java.io.*;
public class a5 {
    public static void main(String[] args) {
                int Number[ ] = new int [100];        
                file("D:\\a.txt");
        }
        public void file(String file) {
        List<String[]> data = new ArrayList<>();
        try {
            Scanner in = new Scanner(new File(file));
            while (in.hasNextLine()) {
                String str = in.nextLine();
                data.add(str.split(" ,|"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // list转化为数组
        String[][] result = data.toArray(new String[][] {});
 
        for (String[] strings : result) {
            for (String string : strings) {
                System.out.print(string + " ");
            }
            System.out.println();
        }
    }
}

解决方案 »

  1.   

    D:\\a.txt  里面的内容 贴点内容?
      

  2.   

    说的不是很清楚,根据你的程序修改了一下,不知道下面的合不合你的要求import java.util.*;
    import java.io.*;public class test {
    static List<String>  list= new ArrayList<String>();
    public static void main(String[] args) {
    int Number[] = new int[100];
    file("D:\\a.txt");
    for(int i=0;i<list.size();i++) {
    Number[i]=Integer.parseInt(list.get(i));
    }
    } public static void  file(String file) {
    List<String[]> data = new ArrayList<>();
    try {
    Scanner in = new Scanner(new File(file));
    while (in.hasNextLine()) {
    String str = in.nextLine();
    data.add(str.split(" ,|"));
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    // list转化为数组
    String[][] result = data.toArray(new String[][] {});
    for (String[] strings : result) {
    for (String string : strings) {
        list.add(string);
    }
    }
    }
    }