I am trying to read file from web url
method 1
try {
String fileUrl = "https://github.com/DhyanandraSingh/appointment-mt/StudentInternship.xlsx";
URL url = new URI(fileUrl).toURL();
FileInputStream excelFile = new FileInputStream(new File(url.toString()));
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
but it throw error:
java.io.FileNotFoundException: https:\github.com\DhyanandraSingh\appointment-mt\StudentInternship.xlsx (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
but when i read any local file it will work.
method 2
i also tried but result is same fileNotFoundException
URLConnection connection = new URL(fileUrl).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();