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

关于java的IO流出现一点奇怪的事情,求高人解答一下?
这是我用来读一段数据的代码,并且把每列用"\t"分隔。
public class ParseFileTxt {

FileInputStream fi = null;
BufferedReader br = null;
String newFilePath  = "";
File newFile = null;
FileWriter fw = null;
BufferedWriter bw = null;
public ParseFileTxt() throws Exception {

fi = new FileInputStream("D:\\file\\wttick.txt");
br = new BufferedReader(new InputStreamReader(fi,"GB2312"));
newFilePath  = "D:\\file\\NewFile\\newWttick.txt";
newFile = new File(newFilePath);
fw = new FileWriter(newFile, true);
bw = new BufferedWriter(fw);
}
public static void main(String[] args) throws Exception{
ParseFileTxt parseFile = new ParseFileTxt();
parseFile.parseFile();
}
private void parseFile()throws Exception {
String  temp = "";
while(true){
 String line ="";
 byte[] cbuf = new byte[1024 * 256];
           //首先读取数据241个字节
         int num = fi.read(cbuf, 0, 272);
         if(num<0){
          break;
         }
         //首先读取数据241个字节
  String str1 = new String(cbuf,0,15 , "GB2312").trim();
  String str2 = new String(cbuf,17,20, "GB2312").trim();
  String str3 = new String(cbuf,38,10 , "GB2312").trim();
  String str4 = new String(cbuf,49,10 , "GB2312").trim();
  String str5 = new String(cbuf,60,12 , "GB2312").trim();
  String str6 = new String(cbuf,80,17 , "GB2312").trim();
  String str7 = new String(cbuf,101,11 , "GB2312").trim();
  String str8 = new String(cbuf,113,9 , "GB2312").trim();
  String str9 = new String(cbuf,124,13 , "GB2312").trim();
  String str10 = new String(cbuf,143,9 , "GB2312").trim();
  String str11 = new String(cbuf,155,7, "GB2312").trim();
  String str12 = new String(cbuf,164,8 , "GB2312").trim();
  String str13 = new String(cbuf,174,16 , "GB2312").trim();
  String str14 = new String(cbuf,195,15 , "GB2312").trim();
  String str15 = new String(cbuf,215,27 , "GB2312").trim();
  
  line = str1 + "\t" + str2 + "\t" +str3 + "\t" +str4 + "\t" +str5 + "\t" +str6 
    + "\t" +str7 + "\t" +str8 + "\t" +str9 + "\t" +str10 + "\t" +str11 + "\t" +str12 
    + "\t" +str13 + "\t" +str14 + "\t" + str15 ;
         
  bw.write(line);