0
Beforehand I would like to say that I have already searched in several links indicated here in stackoverflow and other sites as well and I still could not get concrete help (it may be my mistake too).
I need to get a file
found in folder res
, that folder res
this inside the project folder (outside the folder src
to make it clearer).
Right in my program I can do the following ("while in Netbeans")
public static void obter(){
File f = new File("res\\file.txt");
}
in the above method it can read while running in netbeans. Not outside the netbeans. Error generated outside of Netbeans:
res\file.txt (O sistema não pode encontrar o caminho especificado)
Elsewhere in my code I use the code below and it also works in netbeans
File f = new File(this.getClass().getResource("/file.txt").getFile());
in the above method even without specifying the folder res
it can still find while in netbeans. However outside netbeans returns this to me:
file:\C:\Users\User\Documents\NetBeansProjects\TEST\dist\TEST.jar!\file.txt (A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta)
How to get this file.txt
of the briefcase res
even if I code and pass it to any computer?
PS: If I haven’t made it clear please let me know and try to improve my question.
If I open the . jar compiled with Winrar and put the folder res inside, with getResourse I can get access to res? or I can simply create File with "res/file.txt path" ?
– Jonathan CR
Actually, I did, the part about putting it in the jar wasn’t right. , but you can still do it like this: leaves the file inside a res folder inside src to pick up when you’re all in netbeans. and after compiling you copy src only with the files to the same folder as the jar is. and Dae tu usa o primeiro comando File file = new File("src/res/file.txt");
– Rafael Guasselli
I’ll do a test when I have more time, and see if it works, although the res folder is in the netbeans Folder package, that is, if I put File file = new File("res/file.txt") it can already find, so if I compile and put only the folder res along with the . jar he will find only by doing it right? soon I’ll be back with more results..
– Jonathan CR
The way we commented here in the comments worked, just compile and create a src/res/ folder and put the files there that works. but if I don’t want to use the src folder and want to directly use the res folder just include it in the netbeanse Folder package after compiled include that res folder where the . jar, so you don’t need the src folder.. If you want to edit your answer and put this I will already flag as answer. xD vlw
– Jonathan CR