-2

I'm working on application that causes me many problems when working

file1 = "src\\sga\\facturation\\data.ser";
FileInputStream fis = new FileInputrStream(file1);//this works fine on NetBeans

I tried

file1 = "data.ser";
InputStream fis = ClassLoader.getSystemClassLoader().getResourceAsStream(file1);

But nothing; I tried also to change the repertory's path, it told me file not found, I tried even to force the repertory in C:\Folder; where I put my files but nothing works. I tried to delete those lines to see if FileOutputStream works, but it's not the case :( Here's which works on NetBeans

 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file2));

This is my repertory

My Path

Thanks for helping RELATED POSTS NEVER TOLD ME A SOLUTION WHICH WORK, SO IF YOUR ATTENTION WAS TO PUT A -1 ON BEGINING, DO IT AND LEAVE !

John Doe
  • 13
  • 7

2 Answers2

1

Normally you would load a file that's located in your jar with: InputStream is = this.getClass().getResourceAsStream("my/path/to.file"); but you have to be careful that if the jar or the directory the jar is in has a space it bugs out sometimes. I remember trying this like a year ago. Try the jar and the file thats its located in renaming it.

Their might also be a problem with dir permissions, try running your jar like a administrator

Samuel Kodytek
  • 1,004
  • 2
  • 11
  • 23
  • My path to the file is `"src\\sga\\facturation\\data.ser"` but the jar when unzipin, doesn't contain src .... – John Doe May 29 '16 at 08:28
  • @John Doe in the src you should have your .class files and eventually sga//factuarion/data.ser or something like that :P check if you have your files really in your netbeans src folder – Samuel Kodytek May 29 '16 at 08:30
0

FileInputStream resolves relative path based on current working directory. In your IDE working directory may be different from what it is for standalone program. Use absolute path instead.

Basilevs
  • 22,440
  • 15
  • 57
  • 102
  • When I try to this, and printing the patrh I got this: `C:\bla\bla\bla\SGA-Facturation.jar!\sga\facturation\data.ser` And a syntax error on the path :/ – John Doe May 29 '16 at 08:33
  • Well, you can't read archives using File API. URL.openStream() may work – Basilevs May 29 '16 at 08:44
  • How could I use it? will the URL be just the name of file, or all the path? with ou wothout src ?! – John Doe May 29 '16 at 08:50