我正在通过 PrintWriter 保存 3500 x 2000 矩阵。
float[][] nodeSH = new float[3500][2000];
String fullPath = path + name + ".txt";
File file = new File(fullPath);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
PrintWriter out = new PrintWriter(fullPath);
int sizeX = nodeSH.length;
int sizeY = nodeSH[0].length;
out.println(sizeX + "," + sizeY);
String output = "";
for (int x = 0; x < sizeX; x++) {
output = "";
for (int y = 0; y < sizeY; y++) {
output = output + nodeSH[x][y] + ",";
}
output = output.substring(0, output.length() - 1);
out.println(output);
}
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
当我打开文本文件时,它工作得很好,每 9 行比其他行短一点。
- 我也尝试使用 BufferedWriter 运行相同的程序
- 矩阵总是被填充
- 即使保存一个小矩阵也会导致同样的问题
例如看我的:文本文件图片