Java FileNotFoundException:从服务器中的文件夹中检索一组文件
我正在尝试使用Java FileNotFoundException:从服务器中的文件夹中检索一组文件,java,client,download,Java,Client,Download,我正在尝试使用getfile()从服务器获取一组文件,但出现以下异常: java.io.FileNotFoundException:E:\SERVER\SERVER Content\Apps\icons(访问被拒绝) 这是我的密码: DownloadController downloadcontroller = null; try { downloadcontroller = ServerConnector.getServerConnector().getDownloadControll
getfile()
从服务器获取一组文件,但出现以下异常:
java.io.FileNotFoundException:E:\SERVER\SERVER Content\Apps\icons(访问被拒绝)
这是我的密码:
DownloadController downloadcontroller = null;
try {
downloadcontroller = ServerConnector.getServerConnector().getDownloadController();
} catch (NotBoundException ex) {
Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
}
RemoteInputStream file = null;
try {
file = downloadcontroller.getFile("E:\\SERVER\\Server Content\\Apps\\icons");
} catch (IOException ex) {}
public RemoteInputStream getFile(String fileName) throws IOException {
// create a RemoteStreamServer (note the finally block which only releases
// the RMI resources if the method fails before returning.)
//read data
RemoteInputStreamServer istream = null;
try {
File file = new File(fileName);
System.out.println(file.exists());
FileInputStream fileInputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(
fileInputStream);
istream = new SimpleRemoteInputStream(bufferedInputStream);
// export the final stream for returning to the client
//send data
RemoteInputStream result = istream.export();
// after all the hard work, discard the local reference (we are passing
// responsibility to the client)
istream = null;
return result;
} finally {
// we will only close the stream here if the server fails before
// returning an exported stream
if (istream != null) {
istream.close();
}
}
}
Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
无法打开和读取目录,请使用isFile()和isDirectory()方法区分文件和文件夹。
您可以使用list()和listFiles()方法(分别针对文件名和文件)获取文件夹的内容。您还可以指定一个过滤器,用于选择列出的文件子集。错误消息非常简单。您没有该文件夹/文件的权限。这不取决于您的代码。运行代码的用户没有读取文件或目录的权限。@Jens嗯,我已经调整了文件夹权限。但是仍然没有影响层次结构中的所有文件夹和所有文件吗?