如何在文本文件当中实现按列读取?
写了半天提交时竟然出错,晕倒。。。只好把源代码贴上算了
publicstaticvoidconvert(){
longstart=System.currentTimeMillis();
Filefile=newFile("test1.txt");
try{
for(inti=0;i<COLS;i++){
StringBufferline=newStringBuffer();
FileInputStreamfis=newFileInputStream(file);
DataInputStreamin=newDataInputStream(fis);
in.skip(i);
for(intj=i;j<ROWS*(COLS+2);j+=COLS+2){
line.append((char)in.readByte());
in.skip(COLS+1);
}
fis.close();
in.close();
line.append(" ");
GFFile.writeFile("test2.txt",line.toString(),true);
System.out.println("write"+i);
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
System.out.println("time:"+(System.currentTimeMillis()-start));
}
longstart=System.currentTimeMillis();
Filefile=newFile("test1.txt");
try{
for(inti=0;i<COLS;i++){
StringBufferline=newStringBuffer();
FileInputStreamfis=newFileInputStream(file);
DataInputStreamin=newDataInputStream(fis);
in.skip(i);
for(intj=i;j<ROWS*(COLS+2);j+=COLS+2){
line.append((char)in.readByte());
in.skip(COLS+1);
}
fis.close();
in.close();
line.append(" ");
GFFile.writeFile("test2.txt",line.toString(),true);
System.out.println("write"+i);
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
System.out.println("time:"+(System.currentTimeMillis()-start));
}
本文地址:http://www.45fan.com/a/question/71167.html