我想创建一个目录 贴上代码:
public static void main(String[] args) throws IOException {
mkdir("/usr/local/hadoop/file");
listAll("/usr/local/hadoop");
}
/**
* 创建目录
* @param dir 新建目录的路径
* @throws IOException
*/
public static void mkdir(String dir) throws IOException{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
fs.mkdirs(new Path(dir));
fs.close();
}
/**
* 读取某个路径下的目录
* @param dir 目录所在的路径
* @throws IOException
*/
public static void listAll(String dir) throws IOException{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
FileStatus[] stats = fs.listStatus(new Path(dir));
for(int i = 0; i < stats.length; i++){
if(stats[i].isDir()){
System.out.println(stats[i].getPath().toString());
}
}
}
没有报错 但我在eclipse中找不到刚刚创建的目录 刷新也没有 进入linux 用命令查看没有看到
但是我遍历这个路径下的目录时 却能够看我刚刚创建的目录,请问这是咋回事
我的是win7下的eclipse链接的虚拟机
public static void main(String[] args) throws IOException {
mkdir("/usr/local/hadoop/file");
listAll("/usr/local/hadoop");
}
/**
* 创建目录
* @param dir 新建目录的路径
* @throws IOException
*/
public static void mkdir(String dir) throws IOException{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
fs.mkdirs(new Path(dir));
fs.close();
}
/**
* 读取某个路径下的目录
* @param dir 目录所在的路径
* @throws IOException
*/
public static void listAll(String dir) throws IOException{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
FileStatus[] stats = fs.listStatus(new Path(dir));
for(int i = 0; i < stats.length; i++){
if(stats[i].isDir()){
System.out.println(stats[i].getPath().toString());
}
}
}
没有报错 但我在eclipse中找不到刚刚创建的目录 刷新也没有 进入linux 用命令查看没有看到
但是我遍历这个路径下的目录时 却能够看我刚刚创建的目录,请问这是咋回事
我的是win7下的eclipse链接的虚拟机