在自己建立的文件夹下建立文件,可怎么都不对头!!SOS!!

xmtanglyj 2003-09-11 02:34:00
Properties properties = System.getProperties();
String s = new String(properties.getProperty("user.dir"));

File system=new File(s+"\\"+"system");
if(!system.isDirectory()){
system.mkdir();
JOptionPane.showMessageDialog(null,"make a dir");
}

domainInfo=new File(s+"\\system\\domainInfo.ini");
try{
FileWriter fw=new FileWriter(domainInfo.getName(),true);
BufferedWriter bw=new BufferedWriter(fw);
bw.writenewDomain.nodeID+"+"+newDomain.nodeName+"+"+newDomain.bgMapPath+"+ "+newDomain.fatherNodeID+System.getProperty("line.separator"));
bw.close();
fw.close();
}catch(IOException exp){
JOptionPane.showMessageDialog(null,exp.toString()+":: in filewriter");
}

执行的结果是总是在和system平级的目录下建立了domianInfo.ini,

谁能说说错在那里!谢谢!

...全文
69 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmtanglyj 2003-09-15
  • 打赏
  • 举报
回复
try{
if(devices.exists()){
FileReader fr=new FileReader(devices);
BufferedReader br=new BufferedReader(fr);
while((record=br.readLine())!=null){
StringTokenizer token=new StringTokenizer(record,"+");
if(token!=null){
while(token.hasMoreElements()){
//aaaaaaaaaaaaaaaaaa;
}
}
}
}else{
devices.createNewFile();
}
}catch(IOException exp){
JOptionPane.showMessageDialog(null,exp.toString());
}


这样就好了!!

非常感谢大家!!!
pqds 2003-09-11
  • 打赏
  • 举报
回复
堆堆呵呵说得不错
FileWriter fw=new FileWriter(domainInfo.toString(),true);
也可以的!
geyf 2003-09-11
  • 打赏
  • 举报
回复
同意楼上
whyxx 2003-09-11
  • 打赏
  • 举报
回复
to pqds(一个女农民)

System.getProperty("line.separator"));是用来取得当前系统的换行符
whyxx 2003-09-11
  • 打赏
  • 举报
回复
估计问题出在new FileWriter(domainInfo.getName(), true);这句里面
这里的domainInfo.getName()很有可能取到的只是最终的文件名,而不带路径,所以生成的文件总是在默认目录下.换成这个试试domainInfo.getAbsolutePath()
hesi726 2003-09-11
  • 打赏
  • 举报
回复
先暂时去掉bw.writenewDomain.nodeID+"+"+newDomain.nodeName+"+"+newDomain.bgMapPath+"+ "+newDomain.fatherNodeID+System.getProperty("line.separator"));
看看文件创建在哪儿!
如果还不队,


//改成试试
domainInfo=new File(system,"domainInfo.ini");

// 要不,
\\ 全部改成 / 试试!
从来没有遇到过这样的问题!!!
pqds 2003-09-11
  • 打赏
  • 举报
回复
bw.writenewDomain.nodeID+"+"+newDomain.nodeName+"+"+newDomain.bgMapPath+"+ "+newDomain.fatherNodeID+System.getProperty("line.separator"));


应该是你这句话离地问题,line.separator里面存的什么东西!在什么目录下!
pqds 2003-09-11
  • 打赏
  • 举报
回复
Properties properties = System.getProperties();
String s = new String(properties.getProperty("user.dir"));

File system=new File(s+"\\"+"system");
if(!system.isDirectory()){
system.mkdir();

}

File domainInfo=new File(s+"\\system\\domainInfo.ini");
try{

domainInfo.createNewFile();
}catch(IOException exp){

}


这个是正确的呀,看是否你别的地方错误了!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧