路径获取

today1858 2010-09-09 09:33:27
String path=System.getProperty("user.dir");
System.out.println(path);//user.dir指定了当前的路径
path = path.substring(0,path.lastIndexOf("\\"));
System.out.println(path);
File directory = new File(path+"\\test.log");//设定为当前文件夹
FileOutputStream fos=new FileOutputStream(directory.getAbsolutePath(),true);
fos.write("nihaonihao".getBytes());
fos.flush();
fos.close();
try {
System.out.println(directory.getCanonicalPath());//获取标准的路径
System.out.println(directory.getAbsolutePath());//获取绝对路径
} catch (IOException e) {
e.printStackTrace();
}
...全文
144 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
oracle1858 2010-12-30
  • 打赏
  • 举报
回复
不错,支持,经常来

700

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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