Tôi nhận được ngoại lệ: "Lược đồ URI không phải là tệp"Sơ đồ URI không phải là "tệp"
Điều tôi đang làm là cố gắng lấy tên tệp và sau đó lưu tệp đó (từ máy chủ khác) lên máy tính/máy chủ của tôi từ bên trong một servlet.
Tôi có một chuỗi gọi là "url", từ bản ở đây là mã của tôi:
url = Streams.asString(stream); //gets the URL from a form on a webpage
System.out.println("This is the URL: "+url);
URI fileUri = new URI(url);
File fileFromUri = new File(fileUri);
onlyFile = fileFromUri.getName();
URL fileUrl = new URL(url);
InputStream imageStream = fileUrl.openStream();
String fileLoc2 = getServletContext().getRealPath("pics/"+onlyFile);
File newFolder = new File(getServletContext().getRealPath("pics"));
if(!newFolder.exists()){
newFolder.mkdir();
}
IOUtils.copy(imageStream, new FileOutputStream("pics/"+onlyFile));
}
Dòng gây ra lỗi là một trong những điều này:
File fileFromUri = new File(fileUri);
Tôi đã thêm phần còn lại của để bạn có thể thấy những gì tôi đang cố gắng làm.
Cảm ơn này cũng rất hữu ích. – Ankur