java.io.FileNotFoundException: http:\localhost:8080\ipms\upload\1332146087125.jpg (The filename, directory name, or volume label syntax is incorrect.)
http://localhost:8080/ipms/upload/1332146087125.jpg This is the source path and can be opened; exporting can only get pictures through this; but once exporting, the above error will be reported, seeking a solution;
User provided answer 1:
... . How to access io through http... A local physical path such as D:/tomcat/webapps/IPMS/UPLOAD/xxx.jpg
User provided answer 2:
new ImageIcon(new URL("....")).getImage();
User provided answer 3:
Use the contextPath of the request to spell the path behind you /upload/1332146087125.jpg and you can get it
User provided answer 4:
BufferedImage bufferImg = ImageIO.read(new URL(imageurl));
I use it like this, you can use the URL to get the picture
Available methods:
Java module -- read pictures from the network and convert them into Base64 strings
/**
* Convert the image to BASE64 as a string
* @param filename
* @return
* @throws IOException
*/
public static String getImageString(String filename) throws IOException {
InputStream in = null;
byte[] data = null;
try {
//in = new FileInputStream(filename);
in = getInputStreamFromURL(filename);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
throw e;
} finally {
if(in != null) in.close();
}
BASE64Encoder encoder = new BASE64Encoder();
return data != null ? encoder.encode(data) : "";
}
/**
* Read the image from the URL and convert it into a stream.
* @param destUrl
* @return
*/
public static InputStream getInputStreamFromURL(String destUrl){
HttpURLConnection httpUrl = null;
URL url = null;
InputStream in = null;
try{
url = new URL(destUrl);
httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.connect();
in = httpUrl.getInputStream();
return in;
}catch (Exception e) {
e.printStackTrace ();
}
return null;
}
public static void main(String[] args) {
String s = null;
try {
s = getImageString("http://localhost:8080/all/2017/02/09/14/0777a8af971040729998e6f3bd3b3dca.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
System.out.println(s);
}
Use new FileInputStream(filename) to obtain InputStream for local pictures,
Network images need to be processed with new URL(destUrl), then openConnection(), and then obtained with getInputStream().