public static void main(String[] args) throws IOException, URISyntaxException {
String ipaddress = "10.20.220.187";
String folderpath = "C:\\Users\\Administrator\\Desktop\\KS_testData\\";
String fileName = "test.txt";
String inputFileName = "file:\\\\"+ipaddress+"\\"+folderpath+fileName;
System.out.println(" inputFileName "+inputFileName);
File file = new File(inputFileName);
FileReader inputFileReader = new FileReader(file);
BufferedReader inputStream = new BufferedReader(inputFileReader);
String inLine = null;
while ((inLine = inputStream.readLine()) != null) {
System.out.println(inLine);
}
}
在这里,我试图连接到提供的IP地址并读取其中的文件,
指定的文件夹名是共享文件夹,我正在获取fileNotFoundException。
有人能提出我做错了什么吗?
接收的输出为:
inputFileName file:\\10.20.220.187\C:\Users\Administrator\Desktop\KS_testData\test.txt
Exception in thread "main" java.io.FileNotFoundException: file:\10.20.220.187\C:\Users\Administrator\Desktop\KS_testData\test.txt (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.(FileInputStream.java:138)
at java.io.FileReader.(FileReader.java:72)
at com.sv.ppsdemos.remote.RemoteReadAndWrite.main(RemoteReadAndWrite.java:22)