创建目录 java_java怎么创建目录?

File f = new File("D:/test/1.txt");

if(f.isFile()){

f.renameTo(new File("D:/test/2.txt"));//文件重命名

f.delete();//删除文件

}

File f2 = new File("D:/test/2/");

if(f2.isDirectory()){

f2.renameTo(new File("D:/test/3"));//文件夹重命名

f2.delete();//删除文件夹

}

File f4 = new File("D:/test/4/111.txt");

File f44 = new File("D:/test/4/222.txt");

try {

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f4));

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f44));

if(f4.isFile()){

int x =0;

while(-1!=(x=bis.read())){

bos.write(x); //复制文件

}

bos.flush();

bos.close();

String parentFile = f4.getParent(); //获取文件所在文件夹路径

new File(parentFile+"/newFile").mkdir(); //创建新文件夹

File[] list = f4.getParentFile().listFiles(); //获得文件夹内的文件列表,想要做复制就继续重复上面的复制文件

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

友情提示:写代码还是要看api,伸手党难成大器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值