请问对原始对象引用的问题

zlheadof zlheadof 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

public class AvoidOverwritingFile{

public static void main(String args[]){
String filepath = "c://aa//aa.txt";
File aFile= new File(filepath);
FileOutputStream outputFile =null;
if (aFile.isFile()){
File newFile= aFile;
do{
String name=newFile.getName();
int period=name.indexOf('.');
newFile =new File(newFile.getParent(),
name.substring(0,period)+"_old"
+name.substring(period));

}while(!aFile.renameTo(newFile));
System.out.println(aFile.getName());
System.out.println(newFile.getName());
}

try{
outputFile = new FileOutputStream(aFile);
System.out.println("myfile.txt output stream created");

}catch (FileNotFoundException e){
e.printStackTrace(System.err);
}
System.exit(0);
}
}

File newFile= aFile;
String name=newFile.getName();
引用对象到底是什么意思?是引用其值呢?还是别的。
每次运行,name的值是多少?

...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
zlheadof
Java SE 62,620 成员 307,251 内容