java之FileOutputStream

来源:互联网 发布:随机化算法 编辑:程序博客网 时间:2024/06/06 16:43
import java.io.*;public class rui { public static void main(String[] args) throws IOException {if(args.length < 1){System.out.println("涂涂问你要打开哪个文件");System.exit(1);}String fileName = args[0];FileOutputStream fos = new FileOutputStream (fileName);System.out.println("涂涂要开始写东西了:");for(String s : args){fos.write(s.getBytes());System.out.println(s);}fos.close();}}

结果:
F:\work>javac rui.java
F:\work>java rui tu.txt Hello, nice to see you. 我是涂涂!
涂涂要开始写东西了:
tu.txt
Hello,
nice
to
see
you.
我是涂涂!

txt文件内容:
tu.txtHello,nicetoseeyou.我是涂涂!


由于agrs[]以空格为输入字符的分隔符,没有录入空格符,所以txt文件中没有相应的空格符;

txt文件内容被覆盖重写。

0 0
原创粉丝点击