//消除目录结构
List<File> list=allFile(targetPath);
for(File each:list)
{
File file=new File(targetPath+File.separator+each.getName());
each.renameTo(file);
}
//删除空文件夹
File dir= new File(targetPath);
for(File eaFile:dir.listFiles())
{
if(eaFile.isDirectory())
{
eaFile.delete();
}
}
private List<File> allFile(String path)
{
File targetDir=new File(path);
List<File> list=new ArrayList<File>();
for(File each:targetDir.listFiles())
{
if(each.isDirectory())
list.addAll(allFile(each.getPath()));
else
list.add(each);
}
return list;
}
java 消除文件目录结构,布布扣,bubuko.com
java 消除文件目录结构