如何通过可运行的JAR文件保存PNG?

发布于 2025-02-03 13:45:10 字数 1396 浏览 2 评论 0原文

我在解决这个问题时遇到了困难, 我已经创建了一个客户端\服务器端应用程序,并创建了一种方法 从他的侧面到服务器端“发送” PNG文件,然后服务器端“创建”并将图像保存在仅包含图片的软件包中。

当我运行这种通过Eclipse IDE从客户端到服务器端发送图片的方法时 它可以按预期工作,但是当将客户端/服务器端导出到可运行的jar文件中时,我会得到下一个错误:

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();
        }
}

我得到以下错误:

  java.io.io.filenotfoundException:java.io.filenotfoundexception:c:\ users \ inya \ desktop \ src \ src \ guiserverscreens \ test.png(系统无法
 

找到指定的路径)

似乎使用file newfile = new file(system.getProperty(“ user.dir”)+“ \\ src \\ guiserverscreens \\ \\”+msg.getFilename();

不提供想要的结果

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋意浓 2025-02-10 13:45:10

我认为您正在将NetBean中的目录与服务器上的可用内容混合在一起。保存到外部目录,而不是您的SRC目录。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文