Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please use f.isFile() instead of f.exisits. It is a known issue. In server you mistakenly wrote<br/> <code>BufferedReader d=new BufferedReader(new FileReader(s));</code><br/> instead of <br/> <code>BufferedReader d=new BufferedReader(new FileReader(f));</code><br/> Fixed codes</p> <pre><code>import java.io.*; import java.net.*; import java.util.*; public class ft2server { public static void main(String args[])throws IOException { ServerSocket ss=null; try { ss=new ServerSocket(8085); } catch(IOException e) { System.out.println("couldn't listen"); System.exit(0); } Socket cs=null; try { cs=ss.accept(); System.out.println("Connection established"+cs); } catch(Exception e) { System.out.println("Accept failed"); System.exit(1); } PrintWriter put=new PrintWriter(cs.getOutputStream(),true); BufferedReader st=new BufferedReader(new InputStreamReader(cs.getInputStream())); String s=st.readLine(); String str = "/home/milind/Desktop/"; String path = str + s; System.out.println("The requested file is path: "+path); System.out.println("The requested file is : "+s); File f=new File(path); if(f.isFile()) { BufferedReader d=new BufferedReader(new FileReader(f)); String line; while((line=d.readLine())!=null) { put.write(line); put.flush(); } d.close(); System.out.println("File transfered"); cs.close(); ss.close(); } } } </code></pre> <p>Other one</p> <pre><code>import java.io.*; import java.net.*; import java.util.*; public class ft2client { public static void main(String srgs[])throws IOException { Socket s=null; BufferedReader get=null; PrintWriter put=null; try { s=new Socket("127.0.0.1",8085); get=new BufferedReader(new InputStreamReader(s.getInputStream())); put=new PrintWriter(s.getOutputStream(),true); String u,f; System.out.println("Enter the file name to transfer from server:"); DataInputStream dis=new DataInputStream(System.in); f=dis.readLine(); put.println(f); File f1=new File(f); String str = "/home/milind/"; FileOutputStream fs=new FileOutputStream(new File(str,f1.toString())); while((u=get.readLine())!=null) { System.out.println(u); byte jj[]=u.getBytes(); fs.write(jj); } fs.close(); System.out.println("File received"); s.close(); }catch(Exception e) { e.printStackTrace(); System.exit(0); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload