Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.net.*; 
import java.io.*; 
public class Server 
{ 
    public static void main (String [] args ) throws IOException 
    { 
    int filesize=1022386; 
    int bytesRead; int currentTot = 0; 
      try
    {  
    ServerSocket serverSocket = new ServerSocket(9999); 
    Socket socket = serverSocket.accept(); 
    System.out.println("Accepted connection : " + socket);
    BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));    
    String temp=br.readLine();
    System.out.println("The mesage from client is::"+temp);
    PrintStream  pr=new PrintStream(socket.getOutputStream()); 
                String  str = "acknowledgement from server";
                pr.println(str);
             
    byte [] bytearray = new byte [filesize]; 
    InputStream is = socket.getInputStream(); 
    FileOutputStream fos = new FileOutputStream("d:/here/sreethu.doc"); 
    BufferedOutputStream bos = new BufferedOutputStream(fos); 
    bytesRead = is.read(bytearray,0,bytearray.length); 
    currentTot = bytesRead; 
    
    do 
    { 
        bytesRead = is.read(bytearray, currentTot, (bytearray.length-currentTot)); 
        if(bytesRead >= 0) 
        currentTot += bytesRead; 
    } 
            while(bytesRead > -1); bos.write(bytearray, 0 , currentTot); 
            bos.flush(); bos.close(); socket.close();
    }
    catch(Exception ex)
        
    {
        
    }
    }
}
Posted
Updated 5-Aug-14 22:38pm
v2
Comments
Shubhashish_Mandal 6-Aug-14 4:05am    
what you have tried?

1 solution

Java
try{
  // fancycoding
}

catch(Exception ex)
        
{
    ??? WHY EMPTY ???
    ex.printStackTrace(); // this should be in there to see what is wrong (unless you have a proper logging, then the exception should be listed there)
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900