2012-01-23 5 views
0

이 파일 공유 프로그램을 사용하면 로컬 위치에서 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(); 
     } 
    } 

감사합니다 :)

+0

Java 프로그램을 사용하여 네트워크에서 _shared_ 파일에 액세스 하시겠습니까? –

+0

예,이 컴퓨터 1 대를 사용하여 다른 컴퓨터에서 액세스 할 수있는 PC에 폴더를두고 싶습니다. –

+0

완전한 대답을 얻을 수 없기 때문에 ([의견]) [이] (http : /tackoverflow.com/q/2420657/1101070) 그래서 질문을하고 시도해보십시오. –

답변

1

당신은 당신의 JFileChooser의 경로로 "//" + hostname + "/C://"을 사용하고 있습니다. 그것은 유효한 경로가 아닙니다. LAN의 공유 폴더에있는 파일에 액세스하려는 경우 경로는 \\hostname\sharename입니다.

원격 컴퓨터에 공유 폴더가 정의되지 않은 경우에도 C$이라는 C : 드라이브의 "관리 공유"일 수 있으므로 \\hostname\C$을 사용할 수 있습니다. 그러나 공유에 액세스 할 수있는 권한을 가지려면 해당 시스템에서 유효한 사용자로 인증해야합니다. (Java 프로그램에서 경로를 액세스하려고 할 때 어떻게 작동하는지 모르겠습니다 - Windows가 원격 시스템의 로그인 상자를 표시하거나 실패 할 수 있습니다.)

+0

고마워 :) 잘 근무 –

관련 문제