java重命名文件夹(java 重命名文件)
华为云服务器特价优惠火热进行中! 2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。
合作流程: |
本篇文章给大家谈谈java重命名文件夹,以及java 重命名文件对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
微信号:cloud7591如需了解更多,欢迎添加客服微信咨询。
复制微信号
本文目录一览:
- 1、用Java怎么将文档复制到另一个路径下面并改名
- 2、描述在e盘窗口中创建一个文件夹,并且重命名为java的操作方法
- 3、IDEAjava文件重新命名
- 4、java 文件重命名的原理?有效率高的办法吗
- 5、java如何重命名一个文件
- 6、java 文件夹重命名
用Java怎么将文档复制到另一个路径下面并改名
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class A {
public static void main(String[] args) throws Exception {
String url1 = "D:\\a.txt";// 源文件路径
String url2 = "E:\\b.txt";// 目标路径(复制到E盘,重命名为b.txt)
copy(url1, url2);
}
private static void copy(String url1, String url2) throws Exception {
FileInputStream in = new FileInputStream(new File(url1));
FileOutputStream out = new FileOutputStream(new File(url2));
byte[] buff = new byte[512];
int n = 0;
System.out.println("复制文件:" + "\n" + "源路径:" + url1 + "\n" + "目标路径:"
+ url2);
while ((n = in.read(buff)) != -1) {
out.write(buff, 0, n);
}
out.flush();
in.close();
out.close();
System.out.println("复制完成");
}
}
写一个例子
希望对你有帮助

描述在e盘窗口中创建一个文件夹,并且重命名为java的操作方法
首先,按Win+E打开文件管理器
然后双击E盘打开E盘
然后按Ctel+Shift+N新建文件夹
在之后输入“java”即可
如果已经失焦,可以选中新建的文件夹
然后按F2或者在单击一下,就可以重命名了
IDEAjava文件重新命名
1.右键model 然后选择refactor--rename---选择rename module--ok
2.file-- project structure--修改name为新model名
3.修改pom文件中旧项目名替换为新项目名
4.修改文件名,刷新项目OK
java 文件重命名的原理?有效率高的办法吗
调用操作系统api重名文件就是最效率的办法。java应该就是采用的这种办法。
java如何重命名一个文件
/**
* 修改文件名
* @param oldFilePath 原文件路径
* @param newFileName 新文件名称
* @param overriding 判断标志(如果存在相同名的文件是否覆盖)
* @return
*/
public static boolean renameFile(String oldFilePath,String newFileName,boolean overriding){
File oldfile = new File(oldFilePath);
if(!oldfile.exists()){
return false;
}
String newFilepath = oldfile.getParent()+File.separator+newFileName;
File newFile = new File(newFilepath);
if(!newFile.exists()){
return oldfile.renameTo(newFile);
}else{
if(overriding){
newFile.delete();
return oldfile.renameTo(newFile);
}else{
return false;
}
}
}
原文链接:网页链接
如有帮助请采纳(不懂请提问),可以看我主页,欢迎来交流学习;
java 文件夹重命名
package com.nokia;
import java.io.File;
/*
* This is class used for rename the whole file under file folder name*/
public class RenameFile {
public static void main(String args[]) {
/*
* you should change the path E://文件夹 to what you have on your own computer!*/
File fl = new File("E://文件夹"); //这里写上发替换的文件夹路径,注意使用双斜杠
String[] files = fl.list();
File f = null;
String filename = "";
for(String file:files){
f = new File(fl,file);//注意,这里一定要写成File(fl,file)如果写成File(file)是行不通的,一定要全路径
filename = f.getName();
// System.out.println(filename);
/*the string 要替换掉的内容 is the content in your own file string with the name 替换成的内容,
* here you should change the string into what you have.*/
f.renameTo(new File(fl.getAbsolutePath() + "//" + filename.replace("要替换掉的内容", "替换成的内容")));//这里可以反复使用replace替换,当然也可以使用正则表达式来替换了
}
}
}
java重命名文件夹的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 重命名文件、java重命名文件夹的信息别忘了在本站进行查找喔。
