| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 818 人关注过本帖
标题:[求助],创建文件的问题
只看楼主 加入收藏
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
快速回复:[求助],创建文件的问题
数据加载中...
 
   



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

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