Results 1 to 5 of 5
Thread: File transfer in a network
- 08-29-2011, 09:45 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
File transfer in a network
Hi,
everybody i want to send a file in network .i m using serversocket configuration but there is some problem with my code i guess, i m posting ma code thanx for the help in advance..
regards,Java Code:package filet; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.net.*; import java.io.*; public class Filetransfer { public static void main(String[] argv) throws Exception { Socket sock = new Socket("192.168.0.1",1234); byte[] mybytearray = new byte[1024]; InputStream is = sock.getInputStream(); FileOutputStream fos = new FileOutputStream("filetransfeTufar.txt"); BufferedOutputStream bos = new BufferedOutputStream(fos); int bytesRead = is.read(mybytearray, 0, mybytearray.length); bos.write(mybytearray, 0, bytesRead); bos.close(); sock.close(); } public void listenSocket(){ //Create socket connection try{ Socket socket = new Socket("kq6py", 1234); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); } catch (UnknownHostException e) { System. out.println("Unknown host: kq6py.eng"); System.exit(1); } catch (IOException e) { System. out.println("No I/O"); } System.exit(1); } }
shubham
Last edited by Norm; 08-29-2011 at 02:17 PM. Reason: added code tags
- 08-29-2011, 02:16 PM #2
Can you explain what the program does? Does it compile and execute?there is some problem
You need to add calls to the e.printStackTrace() method in your catch blocks to display any errors that occur.
- 08-29-2011, 05:57 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 08-29-2011, 06:11 PM #4
It was like that when I added the code tags. An amateur attempt at code obfuscation?
- 08-29-2011, 06:19 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
file transfer
By prashant in forum NetworkingReplies: 3Last Post: 12-10-2009, 06:46 AM -
Regarding File Transfer in TCP/IP
By manabendra in forum NetworkingReplies: 2Last Post: 08-07-2009, 07:51 AM -
tcp file transfer
By ddj in forum NetworkingReplies: 2Last Post: 03-20-2009, 02:10 PM -
Java File Transfer
By lks0912 in forum Advanced JavaReplies: 0Last Post: 10-23-2008, 12:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks