首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

JAVA怎么将内容添加到文件末尾,要求要在文件末尾的下一行添加

2012-01-16 
JAVA如何将内容添加到文件末尾,要求要在文件末尾的下一行添加?这是我写的一段代码,只是实现在后面添加文件

JAVA如何将内容添加到文件末尾,要求要在文件末尾的下一行添加?
这是我写的一段代码,只是实现在后面添加文件,但是不知道怎么加个换行符号了:
public String Files(String usemm) throws IOException {

System.out.println("写入的值为:"+usemm);
//创建文件的对象,必须指向创建文件的路径
File f1=new File("F:/项目/f1.txt");
if(!f1.exists()){//如果文件不存在,则创建文件
f1.createNewFile();
}
/**FileOutputStream无法写入回车
FileOutputStream fos=new FileOutputStream(f1,true);
byte[] usemms=usemm.getBytes();
fos.write(usemms, 0, usemms.length);
fos.close();*/
 

return null;
}

[解决办法]

Java code
String temp = "\r\n" +usemm; byte[] usemms=temp.getBytes(); fos.write(usemms, 0, usemms.length); 

热点排行