在第一次写这个的时候发现了一个问题,
就是换行的问题,后来用了一个不能判别平台性的方法实现在windows下的换行,
在windows下的换行符是:"/r/n"
在unix下的是"/n";
下面看看代码:
//FileOutputStream的练习 import java.io.*; import java.lang.reflect.Array; class Test { public static void main(String []args) throws IOException { OutputStream os=new FileOutputStream("temp.txt",true); //用Array.getLength(args)查看args里面有多小个元素;要另外加入包. for(int i=0;i<Array.getLength(args);i++) { byte []temp=args[i].getBytes(); os.write(temp); //使换行符转为字节数组 byte []newLine="/r/n".getBytes(); //写入换行 os.write(newLine); } System.out.println("ok."); os.close(); } };
还有比较好的方法是:
String newline = System.getProperty("line.separator");
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP