java jar 运行路径问题_java程序在Eclipse中运行没有问题,打包成.jar文件之后运行后路径出现异常不知道怎么回事?请各位大侠指教...

以下是主要代码如下privatevoidsetMapButtonActionPerformed(java.awt.event.ActionEventevt){//TODOaddyourhandlingcodehere:intshowConfirmDialog=JOptionPane.showConfirmDialog(M...

以下是主要代码如下

private void setMapButtonActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

int showConfirmDialog = JOptionPane.showConfirmDialog(MapPanel.this, "确定要更换地图?", "友情提示", JOptionPane.YES_NO_OPTION);

if (showConfirmDialog == 0) {

JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileFilter(new FileFilter() {

@Override

public boolean accept(File file) {

if (file.isDirectory()) {

return true;

} else {

String fileName = file.getName().toUpperCase();

if (fileName.endsWith(".JPG") || fileName.endsWith(".JPEG") || fileName.endsWith(".GIF")) {

return true;

} else {

return false;

}

}

}

@Override

public String getDescription() {

return "地图格式(.JPG;.JPEG;.GIF)";

}

});

if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {

//String mapPath = this.getClass().getResource("img/map").getPath();

String mapPath = MapProcessor.class.getResource("/img/map").getPath();

new File(mapPath + "/" + dao.getMapName()).delete();

File selectedMapFile = fileChooser.getSelectedFile();

File upLoadFile = new File(mapPath + "/map" + selectedMapFile.getName().substring(selectedMapFile.getName().lastIndexOf(".")));

dao.setMapName(upLoadFile.getName());

try {

InputStream inStream = new FileInputStream(selectedMapFile);

OutputStream outStream = new FileOutputStream(upLoadFile);

int readBytes = 0; // 读取字节数

byte[] buffer = new byte[1024]; // 定义缓存数组

while ((readBytes = inStream.read(buffer, 0, 1024)) != -1) {// 从输入流读取数据到缓存数组中

outStream.write(buffer, 0, readBytes); // 将缓存数组中的数据输出到输出流

}

outStream.close();// 关闭输出流对象

inStream.close();// 关闭输入流对象

} catch (Exception ex) {

Logger.getLogger(MapPanel.class.getName()).log(Level.SEVERE, null, ex);

}

MapPanel.this.mapProcessor.replaceMap("/img/map/" + upLoadFile.getName());

slider.setValue(slider.getValue() + 1);

smallMapLabel.refreshScale();

smallMapLabel.setIcon(new ImageIcon(mapProcessor.zoom(200, 200)));

}

}

}

以下是在控制台出现的异常

D:\>java -jar MapModule.jar

五月 02, 2012 5:07:50 下午 com.mwq.map.MapPanel setMapButtonActionPerformed

严重: null

java.io.FileNotFoundException: file:\D:\MapModule.jar!\img\map\map.jpg (文件名、

目录名或卷标语法不正确。)

at java.io.FileOutputStream.open(Native Method)

at java.io.FileOutputStream.(Unknown Source)

at java.io.FileOutputStream.(Unknown Source)

at com.mwq.map.MapPanel.setMapButtonActionPerformed(MapPanel.java:387)

at com.mwq.map.MapPanel.access$20(MapPanel.java:352)

at com.mwq.map.MapPanel$21.actionPerformed(MapPanel.java:322)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值