FileOutputStream使用说明
- new FileOutputStream(filepath)是会重新创建文件,或者覆盖之前已经存在的内容。
@Test
public void fileoutputstream(){
String path = "D:\\out.txt";
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(path);
String aa = "the north face 小落叶太亮眼啦。而且不与黑色的撞衫,万事只求半称心。";
fileOutputStream.write(aa.getBytes());
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
-
- new FileOutputStream(filepath,true)是会追加到文件的末尾。

@Test
public void fileoutputstream(){
String path = "D:\\out.txt";
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(path,true);
String aa = "人生哪能多如意。况且他妈的就是个衣服。";
fileOutputStream.write(aa.getBytes());
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}