-1
我試圖獲取一組從服務器的文件檢索一組文件從一個文件夾,使用getfile()
,我得到這個異常:java.io.FileNotFoundException:在服務器
java.io .FileNotFoundException:E:\ SERVER \服務器內容\ APPS \圖標(訪問被拒絕)
這裏是我的代碼:
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);
錯誤消息非常簡單。您沒有該文件夾/文件的權限。 – ares 2014-09-11 09:21:57
這不取決於您的代碼。運行代碼的用戶沒有權限讀取文件或目錄。 – Jens 2014-09-11 09:22:38
@Jens嗯,我調整了文件夾的權限。但仍然沒有效果 – 2014-09-11 10:32:43