改成:
     DataOutputStream dout=new DataOutputStream(new  FileOutputStream("13.txt"));
     for(int i=1;i<4;i++)
     dout.writeInt(i);
     DataInputStream inr=new DataInputStream(new FileInputStream("13.txt"));
     ret=inr.readInt();因为DataOutStream是低级流,把4个字节直接塞到文件里
而InputStreamReader 则是以字符形式读取文件的

解决方案 »

  1.   

    fantasyCoder(牛仔+T恤):刚刚我试了一下,编译错误.can not resolve symbol 
    symbol: method readInt();
      

  2.   

    InputStreamReader只能一次读入一个或者两个字节(这根据Chareset决定),
    方法int read() --- Read a single character.
    要一次读取几个字节作为一个字符,那只能用DataInputStream,它包含了
    许多readXXXX方法。
      

  3.   

    import java.io.*;public class IOTest{public static void main(String[] args){
     int ret=0;
    try{
    DataOutputStream dout=new DataOutputStream(new  FileOutputStream("13.txt"));
    for(int i=1;i<4;i++)
    dout.writeInt(i);
            DataInputStream inr=new DataInputStream(new FileInputStream("13.txt"));
            ret=inr.readInt();
            }catch(IOException e){
             }
            System.out.println("Result"+ret);
    }
    }