我想要做的是读取一个文件并使用StringBuilder
来反转文件内部的顺序,即一行字符串。我让它在while循环中工作,但是当我将它添加到一个方法时,它只会打印出原始文件文本。
这是有效的代码;
// File being read....
while ((currentString = s.next()) != null) {
a.insert(0, currentString);
a.insert(0," ");
}
打印
line. this reads it hope I file. this read will program This
这是不起作用的代码;
// File being read....
while ((currentString = s.next()) != null) {
System.out.print(reverse(currentString));
}
方法
public static StringBuilder reverse(String s){
StringBuilder a = new StringBuilder();
a.insert(0, s);
a.insert(0," ");
}
打印
This program will read this file. I hope it reads this line.
我究竟做错了什么?