1

I'm having trouble fixing this issue, I have created a Client\Server side application and created a Method where a user can "Send" a PNG file from his side to Server side, then the Server side "Creates" and saves the image in a Package that only contains pictures.

When i run this Method of sending a Picture from Client side to Server side via Eclipse IDE it works as expected, but when exporting Client/Server side into Runnable JAR files, i get the next error:

Java

private static void getImg(MyFile msg) {
    int fileSize =msg.getSize();
      System.out.println("length "+ fileSize);
        try {
            File newFile = new File(System.getProperty("user.dir")+"\\src\\GuiServerScreens\\"+msg.getFileName());
            FileOutputStream fileOut;
            fileOut = new FileOutputStream(newFile);
            BufferedOutputStream bufferOut = new BufferedOutputStream(fileOut);
            try {
                bufferOut.write(msg.getMybytearray(), 0,  msg.getSize());
                fileOut.flush();
                bufferOut.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
}

I get the follow error :

java.io.FileNotFoundException: java.io.FileNotFoundException: C:\Users\Ilya\Desktop\src\GuiServerScreens\test.png (The system cannot

find the path specified)

It seems that using File newFile = new File(System.getProperty("user.dir")+"\\src\\GuiServerScreens\\"+msg.getFileName());

Does not provide the wanted result

Soske
  • 541
  • 1
  • 4
  • 10
  • `System.getProperty("user.dir")` returns the path the user is currently in within the Command Prompt. In your IDE, this is typically the root of the project, which explains why it works in your IDE. If you `cd` to your project directory then it should work. – blacktide Jun 01 '22 at 16:33
  • Make a directory off `File(System.getProperty("user.home")` and use that – g00se Jun 01 '22 at 16:39
  • @blacktide how could i use CD? i have tried using "user.home" but this just gives me a local address, but i would like it to store within my Jar file. – Soske Jun 01 '22 at 19:27

1 Answers1

0

I think you are mixing what your directories look like in netbeans with what's available on the server. Save to an external directory instead, not to your src directory.

  • What do you mean by "external directory"? is there no method of accessing the directory of the Runnable JAR and saving it within the packages there? – Soske Jun 01 '22 at 19:28