当前位置: 代码迷 >> J2SE >> 如何在txt文件中输入回车符
  详细解决方案

如何在txt文件中输入回车符

热度:2493   发布时间:2013-02-25 00:00:00.0
怎么在txt文件中输入回车符?
try {
FileInputStream f1=new FileInputStream("c:/test2.txt");
FileChannel c=f1.getChannel();
FileOutputStream f2=new FileOutputStream("c:/test.txt",true);
FileChannel c1=f2.getChannel();
ByteBuffer fb=ByteBuffer.allocate(1024);
try {
c.read(fb);
fb.put("/r/n".getBytes());
fb.flip();

c1.write(fb);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
怎么样让输入到test.txt中的内容另起一行?就用通道这种方式。

------解决方案--------------------------------------------------------
\r\n
------解决方案--------------------------------------------------------
\r\n
------解决方案--------------------------------------------------------
直接
print("\r\n");
  相关解决方案