以下に示すように:
java.io.filewriter; Import java.io.ioexception; Import java.io.randomaccessfile;/***ファイルの最後にコンテンツを追加します。 * @author haicheng.cao * */public class appendtofile {/** *メソッドにファイルを追加する:ランダムアクセスファイルを使用 */public static appendmethoda(string filename、string content){try {//ランダムアクセスファイルストリームを開き、ランダムアクセスファイルランダムファイル= new randomacessfile(filenamame(filename); //ファイルの長さ、バイト数long filelength = randomfile.length(); //ファイルの最後に書き込みファイルポインターを移動します。 randomfile.seek(filelength); randomfile.writebytes(content); randomfile.close(); } catch(ioexception e){e.printstacktrace(); }} /** *メソッドb追加ファイル:ファイルライターを使用 * /public static void appendmethodb(string filename、string content){// filewriterを開くと、コンストラクターの2番目のパラメーターは、apped form 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";文字列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)を表示します。 }}ファイルの最後にJavaが追加したコンテンツの上記の簡単な例は、エディターが共有するすべてのコンテンツです。私はそれがあなたに参照を与えることができることを願っています、そして私はあなたがwulin.comをもっとサポートすることを願っています。