我想用Format class:
对这个简单的文本文件(行长度为80)进行右对齐每个空格都是[TAB]
|Text|EOL
| Text Text|EOL
| Text Text Text|EOL
| Text Text Text Text|EOL
| Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
这是我写的代码:
public static void justify(){
try(
BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Szymon\\Desktop\\textfile.txt"));
PrintWriter out = new PrintWriter("C:\\Users\\Szymon\\Desktop\\textout.txt")
) {
while(in.ready()){
String line = in.readLine();
out.format("%80s\n", line.trim()); // ?
}
} catch (Exception e){
e.printStackTrace();
}
}
但是输出并不是我所期望的:
| Text|EOL
| Text Text|EOL
| Text Text Text|EOL
| Text Text Text Text|EOL
| Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
| Text Text Text Text Text Text|EOL
我做错了什么?