IOStream 是按字节读取的,所以读到的不是确切的数字,显示的有时候是ASCCII码我的解决方法是,先用String读入,然后再转成INT数字,有没有更直接的方法?

解决方案 »

  1.   

    用别的也得转,你的方法可以。如果直接按子节读取后,在把ASCCII码转化成数字,这样叶挺
    麻烦的。
      

  2.   

    [code]
    public class ReadIntTest {        public static void main(String[] args) {
                    try {
                            FileInputStream fis = new FileInputStream("c:\\temp\\int.txt");
                            InputStreamReader isr = new InputStreamReader(fis);
                            LineNumberReader lnr = new LineNumberReader(isr);
                            String s = null;
                            int i;
                            while ((s = lnr.readLine()) != null) {
                                    i = Integer.parseInt(s);
                                    System.out.println("The decimal read: " + i);
                            }
                    } catch (Exception e) {
                            e.printStackTrace();
                    }
            }
    }
    [/code]
    int.txt中每行一个数字
      

  3.   


    public class ReadIntTest {        public static void main(String[] args) {
                    try {
                            FileInputStream fis = new FileInputStream("c:\\temp\\int.txt");
                            InputStreamReader isr = new InputStreamReader(fis);
                            LineNumberReader lnr = new LineNumberReader(isr);
                            String s = null;
                            int i;
                            while ((s = lnr.readLine()) != null) {
                                    i = Integer.parseInt(s);
                                    System.out.println("The decimal read: " + i);
                            }
                    } catch (Exception e) {
                            e.printStackTrace();
                    }
            }
    }