ファイルを消去または消去せずにファイルに行を書き込む方法を知りたい。どんなクラスとパッケージが必要ですか? FileOutputStreamとPrintStream(printlnを使用)とBufferedWriterとOutputStreamWriter(writeを使用)を試しましたが、ファイルから以前の内容が消去されています。前の内容を消去せずにtxtファイルに書き込む
あなたがwriteStringToFile org.apache.commons.io公共の静的な無効writeStringToFile(ファイルのファイル、 文字列データ、 文字セットエンコーディング、 ブールAPPEND)からクラスのfileutils下の方法を使用することができます
try
{
File txt = new File("marcos.txt");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
writer.write(registro);
writer.newLine();
writer.close();
}
catch(Exception e)
{
System.out.println("Error en la escritura al archivo.");
}