当我使用内容为:
的文件运行它时
S O R T E X A M P L E
H e l l o
W o r l D
在第1行和第2行之间打印空格,如下所示:
s o r t e x a m p l e
h e l l o
w o r l d
如何删除空格?
这是代码
import java.util.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException{
//if(args.length==0){
//return;}
List<String> result = new LinkedList<>();
FileReader text = new FileReader(args[0]);
BufferedReader br = new BufferedReader(text);
try {
String Line = br.readLine();
while(Line!=null){
result.add(Line.toLowerCase()); //apply method on individual Lines here!!
Line = br.readLine();
}}
finally{br.close();}
for(int i =0;i<result.size();i++){
System.out.println(result.get(i));
}
}
}
答案 0 :(得分:0)
您可能在第一行\n
参见此示例
List<String> line=new LinkedList<>();
line.add("abn\n"); // You might be having a new Line character
line.add("bce");
line.add("def");
for(String s:line){
System.out.println(s);
}
所以你的输出包含就像这样
abn
bce
def