java - 在 .txt 文件中保存一个巨大的矩阵会弄乱换行符
问题描述
我正在通过 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 运行相同的程序
- 矩阵总是被填充
- 即使保存一个小矩阵也会导致同样的问题
例如看我的:文本文件图片
解决方案
推荐阅读
- hbase - Geomesa IN 查询性能
- javascript - Vue md-input 与 Vuex 仅在一个方向更新
- laravel - API根据用户类型给出结果
- android - 即使在检查用户是否登录后,我的应用程序也会继续将我带回注册页面
- node.js - Puppeteer:空子数组
- arrays - 如何在 React Native 中循环数组
- sql - 查找附近的 Plus 代码
- excel-formula - 带有公式的名称和 ID
- c# - 在 Blazor 中找不到类型或命名空间名称“UIFocusEventArgs”和“LocalDate”
- r - 使用超过 30 个预测变量时 MuMin pdredge() 中的错误