如何解决此错误?我找不到使用不同路径的解决方案,即使是手动的。请解释如何使用绝对路径将图像读入缓冲图像。
private BufferedImage[] image = new BufferedImage[9];
private int imageNo = 0;
private Boolean draw = false;
private int drawType;
private String [] realtivePath;
private String [] absolutePath;
//=============================================================================
public DrawPanel() {
int i,j;
absolutePath = new String[9];
realtivePath = new String []{"B_Pictures\\Burj Khalifa.jpg", "B_Pictures\\Taipei 101.jpg", "B_Pictures\\Willis Tower.jpg",
"B_Pictures\\Empire State Building.jpg", "B_Pictures\\Chrysler Building.jpg",
"B_Pictures\\Woolworth Building.jpg", "B_Pictures\\Met Life Tower.jpg",
"B_Pictures\\Singer Building.jpg", "B_Pictures\\Philadelphia City Hall.jpg"};
//======================================================================
for(i = 0;i < 9; i++)
{
absolutePath[i] = new File(realtivePath[i]).getAbsolutePath();
System.out.println("Path is: "+absolutePath[i]);
}
//=======================================================================
try {
for (j = 0; j < 9; j++) {
image[j] = ImageIO.read(new File(absolutePath[j])); //<-- can't read absolute path!
}
}catch (IOException e) {
e.printStackTrace();
//System.out.println("Error reading file");
}