所以我试图改变一个文本文件的格式,它每隔几行就有一个行号,只是为了让它更干净、更容易阅读。我做了一个简单的程序,将一行的前三个字符全部替换为空格,这三个字符空格是数字所在的位置。实际文本要等到几个空格才开始。当我这样做并打印出最终结果时,它会出现一个带有问号的菱形,我假设这是缺少字符的结果. 似乎大多数缺失的字符都是撇号。如果有人可以让我知道如何解决它,我将不胜感激:)
public class Conversion {
public static void main(String args[]) throws IOException {
BufferedReader scan = null;
try {
scan = new BufferedReader(new FileReader(new File("C:\\Users\\Nasir\\Desktop\\Beowulftesting.txt")));
} catch (FileNotFoundException e) {
System.out.println("failed to read file");
}
String finalVersion = "";
String currLine;
while( (currLine = scan.readLine()) !=null){
if(currLine.length()>3)
currLine = " "+ currLine.substring(3);
finalVersion+=currLine+"\n";
}
scan.close();
System.out.println(finalVersion);
}
}