日期:2014-05-20  浏览次数:20713 次

文件读写的问题
aaaaaaaa

AAdasdas
sdfertbv
wetrebvc

aaaaaaa

BBsadas

aaaaaaaa

AAwedasd

---------------------------------------------
我怎莫从txt文件中读出来
读出来的格式是先读出一排小写a,然后再读出以大写AA为开头的三行

读出来应该是
aaaaaaaa
AAdasdas
sdfertbv
wetrebvc
aaaaaaaa
AAwedasd

那位大哥请赐教




------解决方案--------------------
import java.io.*;

class iotxt{
public static void main(String []args){
BufferedReader input=null;
try{
input=new BufferedReader(new FileReader( "d:/test.txt "));
String buf;
while((buf=(String)input.readLine())!=null){
if((buf.length())> 0){
System.out.println(buf);
}
}
}catch(FileNotFoundException e){
System.out.println( "can 't file the file ");
}catch(IOException e){
e.printStackTrace();
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
}
}
}
}