Windows下Java File对象创建文件夹时的一个"坑"
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对象创建文件夹时的一个"坑"的更多相关文章
- Java中对象JSON格式化处理时的一个坑
在项目中遇到了一个JSON的坑.记录下. 直接上代码: import java.util.ArrayList; import com.alibaba.fastjson.JSON; public cla ...
- Idea创建文件夹自动合成一个
在idea中创建文件夹时,它们总是自动合成一个,如下图: 文件夹自动折叠真的很影响效率,可能会引发一些不经意的失误 解决方法: 取消这个地方的勾选 这样就可以正常创建文件夹了
- windows下使用RoboCopy命令进行文件夹增量备份
RoboCopy,它是一个命令行的目录复制命令,自从Windows NT 4.0 开始就成为windows 资源工具包的一部分,然后在Windows Vista.Windows 7和 Windows ...
- java 按天创建文件夹
按天创建文件夹,也就是每天创建一个,适合上传文件服务使用,文件数量较多时可以按文件夹区分. public static final String FMT = "yyyy-MM-dd" ...
- windows下更换MySql数据库数据文件夹位置
详细解决地址 ,感谢博主 :https://blog.csdn.net/u010953266/article/details/56499361 概述 由于更换硬盘,系统重新安装了一遍,原来的mysq ...
- Linux下修改默认字符集--->解决Linux下Java程序种中文文件夹file.isDirectory()判断失败的问题
一.问题描述: 一个项目中为了生成树状目录,调用了file.listFiles()方法,然后利用file.isDirectory()方法判断是否为目录,该程序在windows下运行无问题,在Linux ...
- Windows下的MySQL删除data文件夹后……
MySQL删除data文件夹后,怎么都无法启动了,出现错误: 150106 9:28:43 [Note] Plugin 'FEDERATED' is disabled. wampmysqld: Tab ...
- mac环境下java项目无创建文件的权限
1.问题: 先抛问题,由于刚刚换用mac环境,之前windows上开发的代码调试完毕,还未上线.之后上线部署之前,tl直连测试本地环境(mac)环境,功能无法使用,显示java.io.IOExcept ...
- sls语法:创建file,创建文件夹
http://blog.kukafei520.net/html/2014/942.html /tmp/aaa.txt: file.managed /tmp/salt_test: file.direct ...
随机推荐
- 谈网页游戏外挂之用python模拟游戏(热血三国2)登陆
看web看多了,想写写页游的外挂,其实原理是一样的,就是端口不一样协议字段你不知道,而这也提高了点技术门槛,看我们来一点一点突破这些门槛,这次我们来用python发包模拟flash的客户端登陆. 以热 ...
- LintCode-Fast Power
Calculate the an % b where a, b and n are all 32bit integers. Example For 231 % 3 = 2 For 1001000 % ...
- LintCode-Word Segmentation
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- Careercup - Google面试题 - 5732809947742208
2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...
- Asp.net 同时下载多个文件
整理自网络 下载思路是首先把多个文件进行压缩,然后再下载压缩成的压缩包 引用文件dll:ICSharpCode.SharpZipLib.dll 1. 合成下载文件夹 Protected Sub btn ...
- jquery 取值赋值
<input type="text" id="range_complete" /> $('#range_complete').val();//取值 ...
- JAVA 获取系统环境变量
分享代码: package com.base.entity; import java.io.Serializable; import java.util.Comparator; /** * 系统环境变 ...
- HDU 4101 Ali and Baba
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4101 一看之下以为是博弈,后来分析才知道只是搜索题. 首先,我们需要从值为-1的位置由内向外搜索一次, ...
- asynDBcenter(复习)
asynDBCenter asynDBCenter是GS和DBCenter之间的模块,有了他GS访问数据库就是异步的了,以前是同步的,加入某个操作很耗时那么GS就在那等待这个返回值. .对于std:: ...
- 有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面m个数。
#include<stdio.h> #include<stdlib.h> int main() { setvbuf(stdout,NULL,_IONBF,); //使用Ecli ...