我正在尝试从网址
中读取文件 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();
}
但它会引发错误:
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)
但是当我读取任何本地文件时它会起作用。
我也试过,但结果是fileNotFoundException
URLConnection connection = new URL(fileUrl).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();