java io write file
I use a client to send file to server, however, i can send the file with equal size, equal filename and filesize. But when i opened the sent file in the server, the file is a blank one. I would like to ask how to solve that
client side
try{
s = new Socket(ServerIP, ServerPort);
File f = new File(sentFile.getName());
fis = new FileInputStream(f);
os = s.getOutputStream();
while (fis.available()>0){
os.write(fis.read());
}
fis.close();
os.close();
s.close();
}catch(IOException ioe){
System.out.println("Get a Error in socket");
}
server side
try{
ss = new ServerSocket(port);
}catch(IOException e){
System.out.println(e);
}
while (true){
try{
s = ss.accept();
fos = new FileOutputStream(new File(filename));
is = s.getInputStream();
for (int i=0; i<fileSize; i++)
fos.write(is.read());
thank you for your help
|