2012-01-23 8 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台のコンピュータのIPアドレスを使用して別のコンピュータからアクセスできるPC上のフォルダを持っています –

+0

私はあなたのために完全な答え(したがってコメント)を持っていませんが、[こちら](http:/sackoverflow.com/q/2420657/1101070)SOの質問とそれを試してみてください。 –

答えて

1

あなたはJFileChooserためのパスとして"//" + hostname + "/C://"を使用しています。それは有効な方法ではありません。 LAN上の共有フォルダにあるファイルにアクセスしようとすると、そのパスは\\hostname\sharenameのようになります。

リモートマシンに共有フォルダが定義されていない場合でも、C$と呼ばれるC:ドライブの「管理共有」の可能性がありますので、\\hostname\C$を使用できます。しかし、共有にアクセスする権限を持つには、そのシステム上の有効なユーザーとして認証する必要があります。 (Javaプログラムからのパスにアクセスしようとすると、どのように動作するのか分かりません.Windowsがリモートシステムのログインボックスを表示するか、失敗する可能性があります)

+0

ありがとう:)うまく働いた –