/*****************************************************************
- public class AppendToFile {
-
- public static void appendMethodA(String fileName, String content) {
- try {
-
- RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
-
- long fileLength = randomFile.length();
-
- randomFile.seek(fileLength);
- randomFile.writeBytes(content);
- randomFile.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- public static void appendMethodB(String fileName, String content) {
- try {
-
- FileWriter writer = new FileWriter(fileName, true);
- writer.write(content);
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public static void main(String[] args) {
- String fileName = "C:/temp/newTemp.txt";
- String content = "new append!";
-
- AppendToFile.appendMethodA(fileName, content);
- AppendToFile.appendMethodA(fileName, "append end. \n");
-
- ReadFromFile.readFileByLines(fileName);
-
- AppendToFile.appendMethodB(fileName, content);
- AppendToFile.appendMethodB(fileName, "append end. \n");
-
- ReadFromFile.readFileByLines(fileName);
- }
- }
摘自:http://jaczhao.iteye.com/blog/1616716
关于java读取文件的几种方式
原文:http://www.cnblogs.com/whsa/p/4256136.html