Hello everyone, there is a code to display the contents of the file on the Internet. I need to display content from 2 files in toast. here is the full activation code
package com.example.byfile; import android.os.Bundle; import com.example.byfile.R; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.net.*; import java.io.*; import java.nio.charset.Charset; public class MainActivity extends Activity { Button btnSend; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); final Button btnSend = (Button)this.findViewById(R.id.btnSend); btnSend.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { new Thread(new Runnable() { @Override public void run() { try { final URL myURL = new URL("http://мой-сайт/1.txt"); final URLConnection connection = myURL.openConnection(); connection.setDoInput(true); final Reader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8"))); final URL myURL2 = new URL("http://мой-сайт/2.txt"); final URLConnection connection2 = myURL2.openConnection(); connection2.setDoInput(true); final Reader reader2 = new BufferedReader(new InputStreamReader(connection2.getInputStream(), Charset.forName("UTF-8"))); try { //буфер 1 final char [] buffer1 = new char[1024]; final StringBuilder message = new StringBuilder(); int readCount; do { readCount = reader.read(buffer1); message.append(buffer1); } while (readCount >= buffer1.length); //буфер 2 final char [] buffer2 = new char[1024]; final StringBuilder message2 = new StringBuilder(); int readCount2; do { readCount2 = reader2.read(buffer2); message2.append(buffer2); } while (readCount2 >= buffer2.length); MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this.getApplicationContext(), message + message2.toString(), Toast.LENGTH_LONG).show(); } }); } catch (final IOException ex) { Log.d("IOException", ex.getMessage()); } finally { reader.close(); } } catch (final Exception ex) { Log.d("Some exception", ex.getMessage()); } } }).start(); } }); }}