日期:2014-05-20 浏览次数:21007 次
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("D:\\workspace\\test\\src\\test.txt"));
List<String> lines = new ArrayList<String>();
while(true){
String line = reader.readLine();
if(line == null){
break;
}else if(line.matches("\\s*")){
continue;
}else{
if(lines.indexOf(line) == -1){
lines.add(line);
}
}
}
for(int i = 0; i < lines.size(); i++){
System.out.println(lines.get(i));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
------解决方案--------------------
String str(String source){
StringBuilder result=new StringBuilder();
boolean number=true;
for(char the:source.toCharArray()){
if(the!='\n'){
number=true;
result.appaned(the);
}else if(number){
result.appaned(the);
number=false;
}
}
}