这三个问题都和RandomAccessFile类有关系这个类自动缓冲文件,并且可以对文件随机访问,可以指定文件指针跳到文件的某个位置再进行操作,使用这个类来追加数据的时候,只需要把文件指针跳到最后,直接写数据就完了,不会造成文件清空,比如:File f=new File("1.txt"); 
RandomAccessFile raf=new RandomAccessFile(f,"rw"); 
raf.skipBytes((int)raf.length()); //文件指针跳到文件尾
raf.writeBytes("hello"); 

解决方案 »

  1.   

    tring line = null;
    int val = 0;
    try {
    BufferedReader is = new BufferedReader(
    new InputStreamReader(System.in));
    line = is.readLine();
    val = Integer.parseInt(line);
    } catch (NumberFormatException ex) {
    System.err.println("Not a valid number: " + line);
    } catch (IOException e) {
    System.err.println("Unexpected IO ERROR: " + e);
    }
    System.out.println("I read this number: " + val);