package class_properties;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.Writer;
import java.util.Properties;
public class Properties_test {
public static void main(String[] args) {
new Properties_test().trans_Properties();
}
public void trans_Properties(){
Properties p = new Properties();
try(InputStream incube = new FileInputStream(this.getClass().getResource("/material/properties_copy").getFile());
) {
p.load(incube);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(p);
String str = "ABC";
try(Writer outcube = new FileWriter(this.getClass().getResource("/material/properties").getFile(),true);
//Writer outcube = new FileWriter("/C:/Users/crf/Desktop/ppp.txt",true);
//Writer outcube = new FileWriter("G:/java/IO_Stream/src/material/properties",true)
){
System.out.println(this.getClass().getResource("/material/properties").getFile());
outcube.write(str);
//p.store(outcube,"properties");
System.out.println(p);
} catch (Exception e) {
e.printStackTrace();
}
}
}
以上代码的Writer outcube 中写入相对路径,为什么不能写入指定内容,但也不报错呢?