Results 1 to 5 of 5
  1. #1
    shubhcool1 is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Smile 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..


    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);
    
    }
    
    }
    regards,

    shubham
    Last edited by Norm; 08-29-2011 at 02:17 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    there is some problem
    Can you explain what the program does? Does it compile and execute?

    You need to add calls to the e.printStackTrace() method in your catch blocks to display any errors that occur.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,654
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by shubhcool1 View Post
    [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.*;
    That is a very freaky layout; did the forum software do that or is it your own invention?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    It was like that when I added the code tags. An amateur attempt at code obfuscation?

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,654
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Norm View Post
    It was like that when I added the code tags. An amateur attempt at code obfuscation?
    People are so creative; they can't program themselves out of a wet paper bag but they torture an accepted layout beyond recognition ;-) This one was scary ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. file transfer
    By prashant in forum Networking
    Replies: 3
    Last Post: 12-10-2009, 06:46 AM
  2. Regarding File Transfer in TCP/IP
    By manabendra in forum Networking
    Replies: 2
    Last Post: 08-07-2009, 07:51 AM
  3. tcp file transfer
    By ddj in forum Networking
    Replies: 2
    Last Post: 03-20-2009, 02:10 PM
  4. Java File Transfer
    By lks0912 in forum Advanced Java
    Replies: 0
    Last Post: 10-23-2008, 12:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •