如何在NetBeans之外写入文本文件 [英] how to write to text file outside of netbeans
问题描述
我很确定有人已经问过这个问题,但我找不到.我该如何写一个文本文件,以便当我从netbeans构建项目时,当将文件构建到.jar中时,仍然可以写该文件.
我在读取文件到.jar时也遇到了问题,但发现我可以使用InputStream
和BufferedReader
.除了写作,还有什么可以做到的吗?
这就是我正在使用的:
I'm pretty sure someone has already asked this but i Can't find it. How can I write to a text file so that when i build the project from netbeans it'll still be able to write the file when its built into the .jar.
I was also having a problem reading file to .jar but found out i could use InputStream
and BufferedReader
. Is there something that can do this but with writing?
This is what I was using:
printf=new PrintWriter(new File("Names.txt"));
但这不适用于在netbeans之外编写. 该文件位于我要写入的jar文件的类中.
but that doesn't work for writing outside of netbeans. The file is inside the classes of the jar file that I want to write to.
推荐答案
给出绝对路径,例如是否要在d:/someFolder
Give absolute path like if you want it in d:/someFolder
printf=new PrintWriter(new File("d:/someFolder/Names.txt"));
请阅读 查看全文