首页 > 解决方案 > 带矩阵的文件 IO

问题描述

我正在尝试接收输入 txt 文件并将相同的文件输出到不同的 txt 文件。但是,我需要将输入文件上的每个矩阵输出到一个二维数组中,并且在每个矩阵之后我想写“行列式:”。我的代码没有像现在这样向输出文件写入任何内容。为什么它不起作用?

FileReader fileReader = new FileReader (inputFilePath); FileWriter fileWriter = new FileWriter (outputFilePath); BR = new BufferedReader(fileReader);

        /**
         * We write out the matrices into the output file and create them to be reference matrix A
         */
        int c; // raw int value from input
        char nextChar; // input cast to char
        long start = System.nanoTime(); //start of execution in nanoseconds
        String line = BR.readLine();
        while((c = fileReader.read()) != -1) {
            nextChar = (char) c;
            int m= line.length();
            int[][]A = new int[m][m];
            for (int i = 0; i < line.length(); i++) {
                for (int j = 0; i < line.length(); j++) {
                    A[i][j] = nextChar;
                }
            }
            String mat = "Determinant: " + A;
            fileWriter.write(mat);
        } // end while

标签: javamatrixfile-io

解决方案


推荐阅读