import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class IOTest01 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
try {
fos = new FileOutputStream("D:\\temp", true);
String s = "\n"+str;
byte[] bytes2 = s.getBytes(StandardCharsets.UTF_8);
fos.write(bytes2);
fos.flush();
fis = new FileInputStream("D:\\temp");
byte[] bytes = new byte[fis.available()];
int readCount = fis.read(bytes);
System.out.println(new String(bytes));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
可以将输入的文本内容添加到文件的下一行。