mercredi 11 mars 2015

File not launching in Client Side Java (Server/Client) App no Web


Vote count:

0




Problem: My File not Launching which is requested from sever.


Okay I have written a server/client application but the problem is when i request for a file from the server it transfer over to the client but what I have notice is that I need to manually refresh the directory to get the file to be in the path or directory. So by saying that, I feel that this is why my code when request the file it doesn't launch.


My approach launching the file from the client after it had just been requested.


Here is my code below:



public static void receiveFile(String fileName) {
try {
int bytesRead;
InputStream in = sock.getInputStream();

DataInputStream clientData = new DataInputStream(in);

fileName = clientData.readUTF();
OutputStream output = new FileOutputStream((fileName));//need to state a repository
long size = clientData.readLong();
byte[] buffer = new byte[1024];
while (size > 0 && (bytesRead = clientData.read(buffer, 0, (int) Math.min(buffer.length, size))) != -1) {
output.write(buffer, 0, bytesRead);
size -= bytesRead;
}

output.close();
in.close();
File file = new File(fileName);
someFunction(file);

//System.out.println("File "+fileName+" received from Server.");
} catch (IOException ex) {
//Logger.getLogger(CLIENTConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}


public static void someFunction(File f){


try {
Desktop.getDesktop().open(f);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


Please can you look are tell me what you think I am doing wrong?



asked 1 min ago







File not launching in Client Side Java (Server/Client) App no Web

Aucun commentaire:

Enregistrer un commentaire