아래 그림과 같이 :
import java.io.filewriter; import java.io.ioexception; import java.io.randomaccessfile;/*** 파일 끝에 컨텐츠를 추가하십시오. * @author haicheng.cao */public class appendtofile {/** * 메소드에 파일 부록 : random acsessfile */public static void appendmethoda (문자열 파일 이름, 문자열 내용) {// 랜덤 액세스 파일 스트림을 열고 randomaccessfile을 읽고 쓰고 쓰기 randomaccessfile (filename, "); // 파일 길이, 바이트 수 긴 filelength = randomfile.length (); // 파일 쓰기 포인터를 파일 끝으로 이동합니다. randomfile.seek (filelength); randomfile.writeBytes (컨텐츠); randomfile.close (); } catch (ioexception e) {e.printstacktrace (); }} /** * 메소드 B 추가 파일 : filewriter * /public static void appendmethodb (String filename, string content) {try {// filewriter를 열면 생성자의 두 번째 매개 변수는 파일을 추가 된 양식 filewriter writer = new Filewriter (filename, true)로 작성하는 것이 참입니다. Writer.write (내용); Writer.close (); } catch (ioexception e) {e.printstacktrace (); }} public static void main (String [] args) {String filename = "c : /temp/newtemp.txt"; 문자열 내용 = "새로운 부록!"; // Append File AppendTofile.appendMethoda (filename, content); AppendTofile.appendMethoda (Filename, "Append End. /n"); // 파일 내용 표시 readfrile.ReadFileByLines (filename); // Append File AppendTofile.appendMethodb (filename, content); AppendTofile.appendMethodb (filename, "append end. /n"); // 파일 내용 표시 readfrile.ReadFileByLines (filename); }}파일 끝에서 Java가 추가 한 컨텐츠의 위의 간단한 예는 편집기가 공유하는 모든 컨텐츠입니다. 나는 그것이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원하기를 바랍니다.