关于java的文件写入的两个问题~~不去学海深仇了有一个变量是account(String的)
建立account.sav格式的文件,应该怎么做?
要是把文件建立在save目录下面又怎么做呢?
myFile = new File("/save",account);
这样可以吗?
谢谢先
学海深仇的斑竹给我打八卦~~~
打死我也不去了[夜不归宿 (5-26 1:00, Long long ago)]
[ 传统版 |
sForum ][登录后回复]1楼
为什么不查API呢?API可是有用的咚咚啊。[乒乒乓乓 (5-26 1:04, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼
ok, this is a basic questionfilename="/home/user/account.sav";
BufferedWriter writer=new BufferedWriter(new FileWriter(filename));
writer.write("whatever you want to write to the line"); writer.newLine();
//finally after u finish
writer.close();
use your own file name... windows file name like "C:/myfolder/saveing.sav";
or relative file locations...
and remember the call function must "throws IOException"
[Cdarkrider (5-26 1:39, Long long ago)]
[ 传统版 |
sForum ][登录后回复]3楼
(引用 Cdarkrider:ok, this is a basic questionfilename="/home/user/account.sav"; BufferedWriter writer=new BufferedWriter(new FileWriter(filename)...)account 是一个变量也可以这么写吗?[夜不归宿 (5-26 1:44, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼
(引用 夜不归宿:account 是一个变量也可以这么写吗?)oh... my godString filename="xxx.txt";
String account="xxx.txt";
String whatever="xxx.txt";
what is the difference???!!!!
please get a book and learn the very basic things first!
[Cdarkrider (5-26 1:48, Long long ago)]
[ 传统版 |
sForum ][登录后回复]5楼
(引用 夜不归宿:account 是一个变量也可以这么写吗?)oh ... my godplease get a book and read the very basic part first before ask further more.
String filename="xxx.txt";
String account="account.txt";
String whatever="xxx.txt";
except "String", no more keyword, you can change of coz!!!![Cdarkrider (5-26 1:50, Long long ago)]
[ 传统版 |
sForum ][登录后回复]6楼
(引用 Cdarkrider:oh ... my godplease get a book and read the very basic part first before ask further more.
String filename="xxx.txt";
String ac...)恩,不要太激动~~~我的意思是这样的
String account=MyInput.readInt();
我要创建的文件是"accout".sav
就是说我想让account随着我的输入而变化
但是扩展名都是sav
这样也可以用上面的方法实现吗?
谢谢你的耐心解答和关注
[夜不归宿 (5-26 1:55, Long long ago)]
[ 传统版 |
sForum ][登录后回复]7楼
(引用 夜不归宿:恩,不要太激动~~~我的意思是这样的
String account=MyInput.readInt();
我要创建的文件是"accout".sav
就是说我想让account随着我的输入...)~~~难道是这样?
String account=account+".txt";
myFile = new File(newaccount);
对吗?
[夜不归宿 (5-26 1:57, Long long ago)]
[ 传统版 |
sForum ][登录后回复]8楼
(引用 乒乒乓乓:为什么不查API呢?API可是有用的咚咚啊。)英文烂~~~[夜不归宿 (5-26 1:58, Long long ago)] [ 传统版 | sForum ][登录后回复]9楼
(引用 夜不归宿:恩,不要太激动~~~我的意思是这样的
String account=MyInput.readInt();
我要创建的文件是"accout".sav
就是说我想让account随着我的输入...)真的建议你有不会的地方好好查查API查相关的class 和 method...
[乒乒乓乓 (5-26 1:58, Long long ago)]
[ 传统版 |
sForum ][登录后回复]10楼
(引用 夜不归宿:英文烂~~~)×_×[乒乒乓乓 (5-26 1:58, Long long ago)] [ 传统版 | sForum ][登录后回复]11楼
(引用 乒乒乓乓:×_×)而且偶是初学~~还是看一点实例的东西比较好~~~[夜不归宿 (5-26 1:59, Long long ago)] [ 传统版 | sForum ][登录后回复]12楼
(引用 乒乒乓乓:为什么不查API呢?API可是有用的咚咚啊。)I thinkHe has not found the usefulness of API, although he was told so.
Hope he would find the API useful later (in CS1102?).
:)[不告诉你 (5-26 2:00, Long long ago)]
[ 传统版 |
sForum ][登录后回复]13楼
(引用 不告诉你:I thinkHe has not found the usefulness of API, although he was told so. Hope he would find the API useful later (in CS1102?). :))看来明年的1102有的受的了~~~说说看先好吗?谢谢了[夜不归宿 (5-26 2:02, Long long ago)] [ 传统版 | sForum ][登录后回复]14楼
(引用 夜不归宿:~~~难道是这样?
String account=account+".txt";
myFile = new File(newaccount);
对吗?
)ok... see this
String account="your directoty/your filename without .txt";
account=account+".txt";
myFile = new File(newaccount);
and can you really "myfile=new File()"? i dont think so.
unless you decleared your own class.
note: pascal style is not working in Java
[Cdarkrider (5-26 2:03, Long long ago)]
[ 传统版 |
sForum ][登录后回复]15楼
(引用 Cdarkrider:ok... see this
String account="your directoty/your filename without .txt";
account=account+".txt";
myFile = new File(newaccount)...)非常感谢你的解答,是少写了一个File新手上路~~
请多指教:$[夜不归宿 (5-26 2:07, Long long ago)]
[ 传统版 |
sForum ][登录后回复]16楼
(引用 夜不归宿:非常感谢你的解答,是少写了一个File新手上路~~ 请多指教:$)welcome[Cdarkrider (5-26 2:08, Long long ago)] [ 传统版 | sForum ][登录后回复]17楼
*_*[辰星 (5-26 18:55, Long long ago)] [ 传统版 | sForum ][登录后回复]18楼
(引用 辰星:*_*)猪婴回家很用功的说。[辰星 (5-26 18:55, Long long ago)] [ 传统版 | sForum ][登录后回复]19楼