Note that there are some explanatory texts on larger screens.

plurals
  1. POSend .txt file, document file to the server in android
    primarykey
    data
    text
    <p>I am developing an application in which I am sending data in string format to the server. Below is my code. It is working fine. But now my question is how can I send whole .txt file and .doc file to the server. In my GUI I have to provide path of user choice. Means user has to choose the path of file that he/she wants to send...Please help me to solve my problem...Thank you...</p> <p>activity_main.xml file</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;EditText android:id="@+id/editText1" android:layout_width="170sp" android:layout_height="40sp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="16dp" android:ems="10" android:hint="@string/ip" /&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="100sp" android:layout_height="40sp" android:layout_alignBaseline="@+id/editText1" android:layout_alignBottom="@+id/editText1" android:layout_marginLeft="24dp" android:layout_toRightOf="@+id/editText1" android:ems="10" android:hint="@string/port" android:inputType="number" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;EditText android:id="@+id/editText3" android:layout_width="300sp" android:layout_height="200sp" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="38dp" android:ems="10" android:hint="@string/msg" /&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="64dp" android:text="@string/send" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>.java file</p> <pre><code>import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { private Socket client; private PrintWriter printwriter; private EditText etMsg, etIP, etPort; private Button button; private String messsage; int port = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etIP = (EditText) findViewById(R.id.editText1); etPort = (EditText) findViewById(R.id.editText2); etMsg = (EditText) findViewById(R.id.editText3); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub messsage = etMsg.getText().toString(); etMsg.setText(""); port = Integer.parseInt(etPort.getText().toString()); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { client = new Socket(etIP.getText().toString(), port); printwriter = new PrintWriter(client.getOutputStream(),true); printwriter.write(messsage); printwriter.flush(); printwriter.close(); client.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); } }); } } &lt;uses-permission android:name="android.permission.INTERNET" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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