问题描述
fis = new FileInputStream(new File(。)。getAbsolutePath()+/ sudoinput.txt);它试图写入服务器上的这个位置。我不确定这是不是一个可写的
的地方。
$ p $ FILE NAME(fos):::::: :::::::::::: / opt / tomcat / temp /./ sudoinput.txt
文件名(fis)::::::::::::::::: :/ opt / tomcat / temp /./ sudoinput.txt
我想写入
webapps / sudoku / WEB-INF / classes
基本上是
C:\ Users ... \git\sudo-project\sudo\src\main\resources
在Eclipse Windows 7上,我得到这个
错误
src\main\resources\sudoinput.txt(系统找不到指定的路径)
如果我给$
$ b $ $ p $ f $ = new FileInputStream(src / main / resources / sudoinput.txt);
我也试过这个:
fis = new FileInputStream(src\\main\\\\resources\\sudoinput.txt);
但是不起作用。
我应该如何创建一个fileinputstream来写入src / main / resources?
请注意,我正在使用eclipse窗口做开发,并将上传.war文件到一个unix服务器,如果这改变了路径需要指定。
同意Sandiip Patil。如果您的资源中没有文件夹,则路径将为 /sudoinput.txt
或文件夹 /folder_name/sudoinput.txt。
为了从资源获取文件,您应该使用 YourClass.class.getResource(/ filename.txt);
例如
扫描仪扫描程序= new Scanner(TestStats.class.getResourceAsStream(/ 123.txt)) ;
或
Scanner scanner = new Scanner(new FileInputStream(TestStats.class.getResource(/ 123.txt)。getPath()));`
另请看:
If I do this
fis = new FileInputStream(new File(".").getAbsolutePath() + "/sudoinput.txt");
Its trying to write to this location on the server. I am not sure if this is a writableplace.
FILE NAME (fos)::::::::::::::::::/opt/tomcat/temp/./sudoinput.txt
FILE NAME (fis)::::::::::::::::::/opt/tomcat/temp/./sudoinput.txt
I wanted to write to webapps/sudoku/WEB-INF/classeswhich is basically C:\Users...\git\sudo-project\sudo\src\main\resources
On Eclipse Windows 7 I get thiserrorsrc\main\resources\sudoinput.txt (The system cannot find the path specified)if I give
fis = new FileInputStream("src/main/resources/sudoinput.txt");
I have tried this too:
fis = new FileInputStream("src\\main\\resources\\sudoinput.txt");
but doesn't work.
how should I create a fileinputstream to be able to write to src/main/resources ?please note that I am using eclipse windows to do dev and will be uploading the .war file on to a unix server if this changes the way in which the paths need to be specified.
Agree with Sandiip Patil. If you didn't have folder inside your resources then path will be /sudoinput.txt
or in folder /folder_name/sudoinput.txt.
For getting file from resources you should use YourClass.class.getResource("/filename.txt");
For example
Scanner scanner = new Scanner(TestStats.class.getResourceAsStream("/123.txt"));
or
Scanner scanner = new Scanner(new `FileInputStream(TestStats.class.getResource("/123.txt").getPath()));`
Also look at: this
这篇关于如何在src / main / resources中创建一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!