problem regarding transferring file to server using socket connection
<p>I'm able to transfer a file to the server using Java, but I'm not able to transfer the file using socket programming in Android. How do I do this? Here is my Java code:</p>

<pre><code>import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {
    InputStream is;
    OutputStream os;
    FileReader fread;
    BufferedReader bfrewad;
    FileInputStream fis;
    FileOutputStream fos;
    static Socket client;
    String str="";
    static File f1;

    public static void main(String[] args) {
         f1=new File("abc.dat");
        Client c1=new Client();
        try {
            //c1.writeToAlocalfilefortesting();
            client = new Socket("192.168.0.180", 34000);
            System.out.println(client.isBound());
            System.out.println("socket created ");
            c1.createAlinkForFile();    
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            System.out.println("--------"+e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("--------"+e.toString());
            e.printStackTrace();
        }
        catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println("--------"+e.toString()+"-----");
            e.printStackTrace();    
        }
    }

    private void writeToAlocalfilefortesting() throws IOException {
        System.out.println("inside the function");
         //TODO Auto-generated method stub
        int len;
        int count=0;
        System.out.println("here ");
        File file=new File("Nas123456789123.dat");
        System.out.println("file opened");
        fis=new FileInputStream(file);
        System.out.println("getting input stream");
        byte[] buffer =new byte[25];
        os=new FileOutputStream(f1);
        System.out.println("out put stream ");
        //int i=fis.read(buf)
        while((len=fis.read(buffer))&gt;0){
        if(len==25){
            count=count+len;
            fos.write(buffer, 0, len);
            System.out.println("sritten");
        }
        }
    }

    private  void createAlinkForFile() throws IOException {
        // TODO Auto-generated method stub
        os=client.getOutputStream();    
        File file=new File("Nas123456789123.dat");
        fis=new FileInputStream(file);
        byte[] b =new byte[25]; 
        int len1;
        int count1=0;
        while((len1=fis.read(b))&gt;0){
            if(len1==25){
                count1=count1+len1;
                os.write(b, 0, len1);
                os.flush();
                System.out.println("sritten");
            }
       }
    }
}
</code></pre>
