【发布时间】:2019-08-18 21:55:01
【问题描述】:
我已经给出了一个来自谷歌驱动器直接下载图像链接的 URI,我想找到返回的文件的文件扩展名,我必须在 Java 中做什么。
例如链接如下:https://drive.google.com/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k
`
public static String saveImage(String imageUrl, String playlist) throws
IOException {
URL url = new URL(imageUrl);
String fileName = url.getFile();
System.out.println(fileName);
String destName
="./figures"+fileName.substring(fileName.lastIndexOf("/"));
String destName = "../imgUpload/"+playlist;System.out.println(destName);
InputStream is = url.openStream();System.out.println("is-
1"+is);OutputStream os = new FileOutputStream(destName);
System.out.println("is"+is);
byte[] b = new byte[2048];int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
is.close();
os.close();
return destName;
}
`
O/P:-
文件名--/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k 文件名-从链接中提取-/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k
【问题讨论】:
标签: java file-upload jersey image-uploading fileinputstream