(B) Method 1
public void method1 () {
FileWriter fw = null;
the try {
// If the file exists, the additional content; if the file does not exist, create file
File f = new File ( "E : \ dd.txt" );
FW = new new FileWriter (F, to true);
} the catch (IOException E) {
e.printStackTrace ();
}
the PrintWriter the PrintWriter new new PW = (FW);
pw.println ( "additional content");
pw.flush () ;
the try {
fw.flush ();
pw.close ();
fw.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
(c) method 2
public static void method2 (File String, String conent) {
BufferedWriter, OUT = null;
the try {
OUT = new new BufferedWriter, (the OutputStreamWriter new new (
a FileOutputStream new new (File, to true)));
out.write (conent + "\ R & lt \ n-");
} the catch (Exception E) {
e.printStackTrace ();
} {the finally
the try {
the out.close ();
} the catch ( E IOException) {
e.printStackTrace ();
}
}
}
(iv) method. 3
public static void the method3 (fileName String, String Content) {
the try {
// open a random access file stream, both reading and writing
RandomAccessFile randomFile = new RandomAccessFile (fileName, "RW");
// file length, the number of bytes
Long fileLength randomFile.length = ();
// write the file pointer to the end of the file.
randomFile.seek (fileLength);
randomFile.writeBytes (Content "\ R & lt \ n-" +);
randomFile.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
}
How ava additional writing txt file
Guess you like
Origin blog.51cto.com/403573/2425853
Ranking