이 파일 공유 프로그램을 사용하면 로컬 위치에서 mye 파일을 가져올 수 있습니다. JFileChooser 선택기 = 새 JFileChooser ("C : // Users")를 사용하고 싶습니다. IP 주소를 사용하는 서버의 파일. 나는 노력하고있다 String hostname = "192.168.1.1"; 하지만 작동하지 않습니다. 파일 선택기를 열면 내 폴더에 도착합니다. 몇 가지 팁? 사전에IP 주소에 연결 사실 파일 공유 프로그램
public void download(String username) throws RemoteException, NullPointerException{
JFileChooser chooser = new JFileChooser("//" + hostname + "/C://");
chooser.setFileView(new FileView() {
@Override
public Boolean isTraversable(File f) {
return (f.isDirectory() && f.getName().equals("C://"));
}
});
int returnVal = chooser.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName());
} try {
String fileName = chooser.getSelectedFile().getName();
File selectedFile = chooser.getSelectedFile();
//String name = "//" + hostname + "/chatter";
System.out.println(fileName);
//ChatFront cf = (ChatFront) Naming.lookup(name);
String ClientDirectory = getProperty + "/desktop/";
byte[] filedata = cf.downloadFile(selectedFile);
File file = new File(fileName);
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(ClientDirectory + file.getName()));
output.write(filedata, 0, filedata.length);
notifySelf(getUsername(), "You have now downloaded: " + file.getName() + " from the server");
output.flush();
output.close();
} catch (Exception e) {
System.err.println("FileServer exception: " + e.getMessage());
e.printStackTrace();
}
}
감사합니다 :)
Java 프로그램을 사용하여 네트워크에서 _shared_ 파일에 액세스 하시겠습니까? –
예,이 컴퓨터 1 대를 사용하여 다른 컴퓨터에서 액세스 할 수있는 PC에 폴더를두고 싶습니다. –
완전한 대답을 얻을 수 없기 때문에 ([의견]) [이] (http : /tackoverflow.com/q/2420657/1101070) 그래서 질문을하고 시도해보십시오. –