如何用java将txt文件中的一列取出

如题所述

参考代码如下,跟基础的
File f=new File("E:\\test.txt");
FileInputStream fis=new FileInputStream(f);
String temp="";
String result="";
int columnNo=4;
int c1=0;
int c2=0;
while(true){
c1=fis.read();
c2=fis.read();
temp+=(char)c1;
temp+=(char)c2;
if(c1==13&&c2==10){
result+=temp.substring(columnNo, columnNo+1);
temp="";
}
if(c1==-1&&c2==-1) break;
}
System.out.println(result);
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答