追加模式 文件读写

1.方法一

try{

  RandomAccessFile randomFile = new RandomAccessFile(path,"rw");

  long fileLength = randomFile.length();

  randomFile.seek(fileLength);

 

  String str;

  //为了解决乱码问题做如下变换

  byte temp[] = str.getBytes();

  randomFlie.write(temp);

  randomFile.close;

}catch(IOExcteption e){

  e.printStackTrace();

}

 

 

2.方法二

 public static void appendMethodB(String fileName, String content) {
        try {
            //打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
            FileWriter writer = new FileWriter(fileName, true);
            writer.write(content);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

 

 

//补充   以空格把字符串分成若干个

String strLine;
Scanner in = new Scanner(System.in);
strLine = in.nextLine();
String str[] = strLine.split(" "); 从0开始

posted @ 2015-11-03 18:17  喵小喵~  阅读(328)  评论(0编辑  收藏  举报