练习-稀疏数组-文件读写

public static void main(String[] args) throws Exception {
     
        FileReader fileReader = new FileReader("src\\main\\resources\\SparseArr1");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line = "";
        String[][] arrs = new String[11][11];
        int rows = 0;
        while ((line = bufferedReader.readLine()) != null) {
     
            String[] tempArrs = line.split("\t");
            int colums = 0;
            for (String item : tempArrs) {
     
                arrs[rows][colums]=item;
                System.out.printf("%d\t", Integer.parseInt(item));
                colums++;
            }
            System.out.println();
            rows++;
        }
        bufferedReader.close();
        fileReader.close();
        //写入
        writeFile(arrs);
    }

    private static void writeFile(String[][] arrs) throws Exception {
     
        BufferedWriter bw= new BufferedWriter(new FileWriter("src\\main\\resources\\SparseArr2"));
        for (String[] itemArray:arrs){
     
            for (String item:itemArray){
     
                bw.write(""+item+"\t");
            }
            bw.newLine();
        }
        bw.flush();
        bw.close();
    }

你可能感兴趣的:(练习,算法)