import java.io.File;
import java.io.IOException; public class DirCreate { public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String dirStr="D:";
File dir=new File(dirStr);
System.out.println("=================1=================");
System.out.println(dir.getAbsolutePath());
System.out.println(dir.getCanonicalPath()); dir=new File(dirStr+File.separator);
System.out.println("=================2=================");
System.out.println(dir.getAbsolutePath());
System.out.println(dir.getCanonicalPath()); dir=new File(dirStr,"placeholder").getParentFile();
System.out.println("=================3=================");
System.out.println(dir.getAbsolutePath());
System.out.println(dir.getCanonicalPath());
}
}

output:

==================================
D:\testWorkspace//打印的是eclipse的workspace
D:\testWorkspace
==================================
D:\
D:\
==================================
D:\
D:\

解析:

 String java.io.File.getAbsolutePath()

Returns the absolute pathname string of this abstract pathname. 

If this abstract pathname is already absolute, then the pathname string is simply returned as if by the getPath method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, 
which is named by the system property user.dir, is returned.
Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory. Returns:
The absolute pathname string denoting the same file or directory as this abstract pathname
Throws:
SecurityException - If a required system property value cannot be accessed.
See Also:
java.io.File.isAbsolute()

Windows下Java File对象创建文件夹时的一个"坑"的更多相关文章

  1. Java中对象JSON格式化处理时的一个坑

    在项目中遇到了一个JSON的坑.记录下. 直接上代码: import java.util.ArrayList; import com.alibaba.fastjson.JSON; public cla ...

  2. Idea创建文件夹自动合成一个

    在idea中创建文件夹时,它们总是自动合成一个,如下图: 文件夹自动折叠真的很影响效率,可能会引发一些不经意的失误 解决方法: 取消这个地方的勾选 这样就可以正常创建文件夹了

  3. windows下使用RoboCopy命令进行文件夹增量备份

    RoboCopy,它是一个命令行的目录复制命令,自从Windows NT 4.0 开始就成为windows 资源工具包的一部分,然后在Windows Vista.Windows 7和 Windows ...

  4. java 按天创建文件夹

    按天创建文件夹,也就是每天创建一个,适合上传文件服务使用,文件数量较多时可以按文件夹区分. public static final String FMT = "yyyy-MM-dd" ...

  5. windows下更换MySql数据库数据文件夹位置

    详细解决地址 ,感谢博主  :https://blog.csdn.net/u010953266/article/details/56499361 概述 由于更换硬盘,系统重新安装了一遍,原来的mysq ...

  6. Linux下修改默认字符集--->解决Linux下Java程序种中文文件夹file.isDirectory()判断失败的问题

    一.问题描述: 一个项目中为了生成树状目录,调用了file.listFiles()方法,然后利用file.isDirectory()方法判断是否为目录,该程序在windows下运行无问题,在Linux ...

  7. Windows下的MySQL删除data文件夹后……

    MySQL删除data文件夹后,怎么都无法启动了,出现错误: 150106 9:28:43 [Note] Plugin 'FEDERATED' is disabled. wampmysqld: Tab ...

  8. mac环境下java项目无创建文件的权限

    1.问题: 先抛问题,由于刚刚换用mac环境,之前windows上开发的代码调试完毕,还未上线.之后上线部署之前,tl直连测试本地环境(mac)环境,功能无法使用,显示java.io.IOExcept ...

  9. sls语法:创建file,创建文件夹

    http://blog.kukafei520.net/html/2014/942.html /tmp/aaa.txt: file.managed /tmp/salt_test: file.direct ...

随机推荐

  1. MySQL参数调优最佳实践

    前言很多时候,RDS用户经常会问如何调优RDS MySQL的参数,为了回答这个问题,写一篇blog来进行解释: 哪一些参数不能修改,那一些参数可以修改:这些提供修改的参数是不是已经是最佳设置,如何才能 ...

  2. andriod

    谷歌提供的安卓源码中,网址如下:http://androidxref.com http://blog.csdn.net/zoe6553/article/details/6622258

  3. 幻灯片slider

    <script src="{$GetInstallDir}web/scripts/jquery-1.3.1.js"></script> <style& ...

  4. mysql中常用的公式及个人演示

    学生,院系表 -- phpMyAdmin SQL Dump-- version 4.1.9-- http://www.phpmyadmin.net---- Host: localhost-- Gene ...

  5. Ubuntu 14.04 安装 Xilinx ISE 14.7 全过程

    生命在于折腾. 这个帖子作为我安装xilinx ISE 14.7版本一个记录.希望给需要的人一些帮助,这些内容绝大部分也是来源于互联网. 软硬件: lsb_release -a No LSB modu ...

  6. oc对象的内存管理

    oc没有java的垃圾回收机制,所以对象的内存释放很重要,基本数据类型,我们不用理会,编译器会处理: oc的每个对象内部都由一个计数器,用来记录当前有几个指针在指向该对象:当计数器为0时该对象会从内存 ...

  7. FineUI Grid控件右键菜单的实现

    FineUI官方Demo上一直没有Grid右键菜单的实现,其实从4.1.x的版本开始,允许添加自定义的事件监听(Listeners),所以要实现这个功能已经相当容易了. ExtJs右键菜单有很多种,对 ...

  8. map中的erase成员函数用法

    转载于 http://www.cnblogs.com/graphics/archive/2010/07/05/1771110.html  http://hi.baidu.com/sdkinger/it ...

  9. PV操作,

    P操作是先做减一操作,然后判读是否大于等于0. V操作是先做加一操作,然后判断是否大于0

  10. cf 359C

    stl 里的map使用   然后就是快速幂取余 #include <cstdio> #include <cstring> #include <algorithm> ...