まあ、私はこのプログラムを持って、ダウンロードオプションは正常に動作しています。他のコンピュータにアクセスしてそのファイルを自分のデスクトップにダウンロードできますが、アップロードは問題です。ファイルを選択すると、プログラムは他のコンピュータからファイルを取得しようとしますが、そのパスは間違っています。何とかJFileChooserを(私がダウンロードしているように)使用して、自分のコンピュータ名またはIPアドレスを入れることができるのですか?別のコンピュータへのアクセスを試みる前に、私はJFilChooserで動作させるようにしましたが、パスは今すぐ上になります。いくつかのヒントやトリックですか?2台のコンピュータからのファイル共有。
public void upload(String username) throws RemoteException, NullPointerException{
try {
System.out.println(getProperty);
String lol = "/hei/hei.txt";
String ServerDirectory=("//" + "JOAKIM-PC"+ "/Users/Public/Server/");
byte[] filedata = cf.downloadFile2(getProperty + lol);
File file = new File(getProperty + lol);
BufferedOutputStream output = new BufferedOutputStream
(new FileOutputStream(ServerDirectory + file.getName()));
output.write(filedata,0,filedata.length);
output.flush();
output.close();
} catch(Exception e) {
System.err.println("FileServer exception: "+ e.getMessage());
e.printStackTrace();
}
}
public void download(String username) throws RemoteException, NullPointerException{
JFileChooser chooser = new JFileChooser("//" + "JOAKIM-PC" + "/Users/Joakim/Server/");
chooser.setFileView(new FileView() {
@Override
public Boolean isTraversable(File f) {
return (f.isDirectory() && f.getName().equals("Server"));
}
});
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 clientDirectory = getProperty + "/desktop/";
byte[] filedata = cf.downloadFile(selectedFile);
System.out.println("Byte[] fildata: " + selectedFile);
File file = new File(fileName);
System.out.println("fileName: " + fileName);
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(clientDirectory + file.getName()));
output.write(filedata, 0, filedata.length);
output.flush();
output.close();
} catch (Exception e) {
System.err.println("FileServer exception: " + e.getMessage());
e.printStackTrace();
}
}
* 'System.out.println(getProperty);' *あなたは 'getProperty'という名前の属性を持っていますか?それを取得するための 'getGetProperty()'とそれを設定する 'setGetProperty()'はありますか?それは*非常に混乱するに違いない。 –
String getProperty = System.getProperty( "user.home"); –