0
我一直在尝试在某些目录内创建文件,但一直未能弄清楚。文件管理 - 管理java的文本文件
重点是在包dir
:com.resources.files
内创建文本文件,但我的想法不起作用。
public boolean archiveFile() {
//
InputStream str = this.getClass().getResourceAsStream("/com/resources/files/"+Filename.txt
boolean bol = false;
file = new File( str.toString() );
if(!file.exists()) {
try {
file.createNewFile();
bol = true;
} catch (Exception e) {
e.printStackTrace();
}// try-catch
}else {
bol = false;
} // if - else
return bol;
}// archiveFile
new File(str.toString());将无法工作。你有一个流,那么你必须从那里读取。请参阅http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string – Leo 2014-09-23 23:19:49
getClass()。getResourceAsStream是做什么的?第一次看到这 – Coffee 2014-09-23 23:24:46