这个具体怎么实现啊,各位大佬

解决方案 »

  1.   


    public class test16 { public static void main(String[] args) {
    String str,s[];
    try {
    FileReader f1=new FileReader("test.dat"); //路径请配置相应的路径
    FileOutputStream f2=new FileOutputStream("result.txt");//路径请配置相应的路径
    BufferedReader bfr=new BufferedReader(f1);
    DataOutputStream dos=new DataOutputStream(f2);
    while((str=bfr.readLine())!=null) {
     str=str.replace("\r\n", "");
     s=str.split(",");
     dos.writeShort(s[0].length());
     dos.writeChar(',');
     dos.writeChars(s[0]);
     dos.writeChar(',');
     dos.writeShort(s[1].length());
     dos.writeChar(',');
     dos.writeChars(s[1]);
     dos.writeChar(',');
     dos.writeShort(Short.parseShort(s[2]));
     dos.writeBytes("\r\n");
    }
    bfr.close();
    f1.close();
    dos.close();
    f2.close();
    } catch (NumberFormatException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}