Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this weird issue, when I use

File FileToRead = new File("\\MYSERVER\MYFOLDER\MYFOLDER\MYPICTURE.JPG");

to read a file over a network, all I get is a null pointer exception. Normally a local path works with this, but when on a network path, I just couldn't manage to get it to work. Any ideas?

PS: oh and my network connection seems to work, no issues when accessing data in windows explorer...

More of the code:

File FileToRead = new File("file://DOKSERVICE/Somefolder/ProductImage/01001.JPG");
//File FileToRead = new File("c:\dog.jpg"); local test
BufferedImage image = ImageIO.read(FileToRead);
BufferedImage resizedimage = new BufferedImage(260, 260,BufferedImage.TYPE_INT_RGB ); 
Graphics2D g = resizedimage.createGraphics();  
g.drawImage(image, 0, 0, 260, 260, null);  
g.dispose(); 
picture.setIcon(new ImageIcon(image));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
121 views
Welcome To Ask or Share your Answers For Others

1 Answer

Just specify the file path as URI:

File FileToRead = new File(new URI("file://MYSERVER/MYFOLDER/MYFOLDER/MYPICTURE.JPG"));

EDIT note that that string is an URI! It cannot contain spaces so you have to replace them with "%20" to make it work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...