theString如果我在此代码中使用替换方法,为什么还需要重新定义变量:
String theString = "I w@nt to h@ve the regul@r \"A\"!";
theString = theString.replace("@", "a");
System.out.println(theString);
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做:
theString.replace("@", "a");
Run Code Online (Sandbox Code Playgroud)
那就是它?
我正在尝试将文件放在目录中(The system property user.home)/.plantgrower/logs.该文件夹.myprogram不存在,我想用它的子文件夹创建它.这是我的代码:
File f = new File(System.getProperty("user.home") + File.pathSeparatorChar + ".plantgrower" + File.pathSeparatorChar + "logs");
System.out.println(f.mkdirs());
Run Code Online (Sandbox Code Playgroud)
但是,输出是,false并且不创建文件夹.我不明白为什么会这样做.
另一个奇怪的事情:我已经设置了user.home(在我的情况下/home/matthieu)每个人的写作和阅读权限,但f.canWrite()输出false.