如何通过可运行的JAR文件保存PNG?
我在解决这个问题时遇到了困难, 我已经创建了一个客户端\服务器端应用程序,并创建了一种方法 从他的侧面到服务器端“发送” 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在将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.