| | |
Sending files in socket problem///
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 20
Reputation:
Solved Threads: 0
hi,
im working on java on some client server project...
in the project the client and the server can send files, but im failng to do so, the resiver get only part of the file...
here is my code
sender:
resiver::
help....
im working on java on some client server project...
in the project the client and the server can send files, but im failng to do so, the resiver get only part of the file...
here is my code
sender:
Java Syntax (Toggle Plain Text)
public void uploadByteFile(String fileNameToGet, File fileDst) { try { FileReader fileReader = new FileReader(new File("c:\\7.mpg")); BufferedReader bufferedFileReader = new BufferedReader(fileReader); // PrintWriter streamWriter = new PrintWriter(client.getOutputStream()); DataOutputStream streamWriter = new DataOutputStream(client.getOutputStream()); String line = null; PrintWriter outTextStream = new PrintWriter(client .getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(client .getInputStream())); outTextStream.println("start?"); if (in.readLine().matches("start")) { streamWriter.flush(); // streamWriter.flush(); while ((line = bufferedFileReader.readLine()) != null) { streamWriter.writeBytes(line); // System.out.println(line); } out.flush(); } //in.close(); } catch (IOException e) { System.out.println("Error reading from file: " + fileNameToGet); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.out.println("Error wile trying to close a file: " + fileDst.getName()); e.printStackTrace(); } } } }
resiver::
Java Syntax (Toggle Plain Text)
FileOutputStream out = null; try { PrintWriter outTextStream = new PrintWriter(socket .getOutputStream(), true); BufferedReader inTextStream = new BufferedReader( new InputStreamReader(socket.getInputStream())); out = new FileOutputStream("c:\\91.mpg"); int received = 0; byte[] buff = new byte[1024]; int sum = 0; inTextStream.readLine(); outTextStream.println(("start")); DataInputStream in = new DataInputStream(socket.getInputStream()); while ((received = in.read(buff)) > 0) { out.write(buff, 0, received); System.out.println(sum += buff.length); } out.flush(); out.close(); in.close(); in.close(); // out = new FileOutputStream(""); out.close(); out.flush(); out = null; } catch (IOException e) { System.out.println("Error reading from file: "); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.out.println("Error wile trying to close a file: "); e.printStackTrace(); } } }
help....
•
•
Join Date: Jul 2008
Posts: 20
Reputation:
Solved Threads: 0
After long worm hours (the air conditioner is broken) I found the problem the sender and the reviser was using different type of streams I fixed it .. .and the code is attached
enjoy
sender
resiver:
enjoy
sender
Java Syntax (Toggle Plain Text)
try { FileInputStream bufferedFileReader = new FileInputStream( "c:\\7.mpg"); DataOutputStream streamWriter = new DataOutputStream(client .getOutputStream()); String line = null; int line1 = 0; PrintWriter outTextStream = new PrintWriter(client .getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(client .getInputStream())); outTextStream.println("start?"); if (in.readLine().matches("start")) { streamWriter.flush(); byte[] buff = new byte[1024]; while ((line1 = bufferedFileReader.read(buff, 0, 1024)) > -1) { streamWriter.write(buff); System.out.println(buff); } out.flush(); } // in.close(); } catch (IOException e) { System.out.println("Error reading from file: " + fileNameToGet); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.out.println("Error wile trying to close a file: " + fileDst.getName()); e.printStackTrace(); } } }
Java Syntax (Toggle Plain Text)
try { PrintWriter outTextStream = new PrintWriter(socket .getOutputStream(), true); BufferedReader inTextStream = new BufferedReader( new InputStreamReader(socket.getInputStream())); out = new FileOutputStream("c:\\91.mpg"); int received = 0; byte[] buff = new byte[1024]; int sum = 0; inTextStream.readLine(); outTextStream.println(("start")); DataInputStream in = new DataInputStream(socket.getInputStream()); while ((received = in.read(buff)) > -1) { out.write(buff, 0, received); // System.out.println(sum += received); } out.flush(); out.close(); in.close(); } catch (IOException e) { System.out.println("Error reading from file: "); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.out.println("Error wile trying to close a file: "); e.printStackTrace(); } }
![]() |
Similar Threads
- Java Socket Problem (Java)
- Perl FTP Problem (Perl)
- socket problem,,,,, plz help (Java)
- Upload problem of large files in Win 2003 (Windows NT / 2000 / XP)
- Problem with My Project (Missing Files) (Visual Basic 4 / 5 / 6)
- WinSock problems. (C++)
- Problem In using Substring.. (Java)
- Outlook Express 6 not sending attachments (Windows Software)
Other Threads in the Java Forum
- Previous Thread: Random.nextInt(); cannot find symbol
- Next Thread: Java SQL update syntax
Views: 737 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree webservices windows





