Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
资源文件夹中的Java write.txt文件_Java - Fatal编程技术网

资源文件夹中的Java write.txt文件

资源文件夹中的Java write.txt文件,java,Java,我试图在一个资源文件夹中写一个.txt文件,但它什么也不写。我可以通过以下操作读取相同的.txt文件: Scanner scanner = null; InputStream IS = MyClass.class.getResourceAsStream("/File/My FileH"); scanner = new Scanner(IS); 但说到写作,我尝试过: PrintWriter writer = new PrintWriter( new File(this.getClas

我试图在一个资源文件夹中写一个.txt文件,但它什么也不写。我可以通过以下操作读取相同的.txt文件:

Scanner scanner = null;
InputStream IS = MyClass.class.getResourceAsStream("/File/My FileH");
scanner = new Scanner(IS);
但说到写作,我尝试过:

PrintWriter writer =  new PrintWriter(
    new File(this.getClass().getResource("/File/My FileH").getFile()));
writer.println("hello");
writer.close();

有没有关于如何在该文件夹中写入内容的建议?

如果无法在资源中写入内容,请假设您将资源打包为一个jar。Jar是只读的。你不能更新它。您可以提取
jar
并编辑内容


您可以尝试作为替代方法

try
PrintWriter writer=new PrintWriter(新文件(this.getClass().getResource(“/File/My FileH”).getPath())