标题:[求助],创建文件的问题
只看楼主
tqtbj
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2004-8-1
 问题点数:0 回复次数:3 
[求助],创建文件的问题
用什么命令可以在硬盘上创建一个文件呀?
搜索更多相关主题的帖子: 文件 
2004-08-06 20:52
wcwjb
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2004-8-9
得分:0 
我拷不会吧
2004-08-22 20:50
tailys
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2004-8-16
得分:0 

File file = new File("path and file name you want to save");

FileOutputStream fos = new FileOutputStream(file); fos.write(//byte you want to write); fos.close();

或者用FileWriter如果写入的是char流,方便

2004-08-23 01:28
Anstey
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2004-4-14
得分:0 

what i will do is ask the user to specify a path which they want to create the file. The program can be written in a few ways, i.e. using different class, they are gernally three of them, FileWriter, BufferedWriter and PrintWriter, in here i will use PrintWriter, because this is the easiest way.

public class Write{

public static void main(String[] args) throws IOException{

//to use the PrintWriter class which must pass in a FileWriter object as parameter

PrinteWriter pr = new PrintWriter(new FileWriter(agrs[0])); /*args[0] is the first file name specified by the user in the command line, if the file name doesnt exist, it will create a new one*/

pr.println("Whatever you wanna type.");

pr.print("Pretty much the same as using System.out.");

pr.close(); // this is very important

}

}


Anstey. Cheers. I love CAPPUCCINO~~
2004-08-23 14:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-3961-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.381308 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved