import java.io.*;public class FileInputStreamTest {
    public FileInputStreamTest() {
    }
    public static void main(String[] args){
     FileInputStream fls = null;
     File file = null;
     try{
     file = new File("FileInputStreamTest.java");
     fls = new FileInputStream(file);
     while(fls.read()!=-1){
     char ch = (char)fls.read();
     System.out.print (ch);
     }
     fls.close();
     }catch(FileNotFoundException fnfe){
     System.out.println ("找不到文件!!");
     }catch(IOException ioe){
     ioe.printStackTrace();
     }
    }
}
这段代码为干什么运行后的结果是这样?motjv.o*
pbi ls ienuSraTs 
  pbi ienuSraTs( 
  }
  ulcsai odmi(tig]ag)
    ienuSra l  ul
    iefl  ul
    r{
    ie=nwFl(FlIpttemetjv";
    l  e ienuSra(ie;
    hl(l.ed)=1{
    ca h=(hrfsra(;
    Sse.u.rn c)
      }
    l.ls(;
  }ac(ieoFudxeto ne{
    ytmotpitn(?????!";
  }ac(Oxeto o)
    iepittcTae)
    
  }
?郁闷,上面的有的问号我还知道,是因为中文的原因,可是为什么会出现这种情况,打一个字节丢一个字节呢?
请高手赐教,小弟感激不尽。。
谢谢了。

解决方案 »

  1.   


    import java.io.*;public class FileInputStreamTest {
        public FileInputStreamTest() {
        }
        public static void main(String[] args){
            FileInputStream fls = null;
            File file = null;
    int n;
            try{
                file = new File("FileInputStreamTest.java");
                fls = new FileInputStream(file);
                while((n=fls.read())!=-1){
                    //char ch = (char)fls.read();
                    System.out.write (n);
                }
                fls.close();
            }catch(FileNotFoundException fnfe){
                System.out.println ("找不到文件!!");
            }catch(IOException ioe){
                ioe.printStackTrace();
            }
        }
    }