自己补空格 for example String[][] data = {{"1","2","3"}, {"12","123","1234"}}; String buf; PrintStream ps = new PrintStream(new FileOutputStream("test.txt")); for (String[] d : data) { for (String s : d) { ps.printf("%-10s", s); //按10位长度格式化 } ps.println(); } ps.close();
在另一帖子回复了,这边也复制一份格式化保存 String[][] data = {{"1","2","3"}, {"12","123","1234"}}; String buf; PrintStream ps = new PrintStream(new FileOutputStream("test.txt")); for (String[] d : data) { for (String s : d) { ps.printf("%-10s", s); //按10位长度格式化 } ps.println(); } ps.close();
那边已经回答。
for example
String[][] data = {{"1","2","3"}, {"12","123","1234"}};
String buf;
PrintStream ps = new PrintStream(new FileOutputStream("test.txt"));
for (String[] d : data) {
for (String s : d) {
ps.printf("%-10s", s); //按10位长度格式化
}
ps.println();
}
ps.close();
String[][] data = {{"1","2","3"}, {"12","123","1234"}};
String buf;
PrintStream ps = new PrintStream(new FileOutputStream("test.txt"));
for (String[] d : data) {
for (String s : d) {
ps.printf("%-10s", s); //按10位长度格式化
}
ps.println();
}
ps.close();