Lendo um file de text usando InputStream

Como posso ler um file de text como na aplicação Android:

"1.something written 2.in this file 3.is to be read by 4.the InputStream ..." 

então posso retornair uma string como:

  • Reproduzindo o som padrão do Android, clicando no método OnTouch ()
  • Estado progressbair android
  • O Android Widget onReceive não pode chamair a class Service?
  • Pairtindo o aplicativo Android com o button Voltair
  • Como obter os contatos do whatsapp do Android?
  • O que é o avg. Tempo limite de connection ideal paira aplicativo móvel?
  •  "something written\nin this file\nis to be read by\nthe InputStream" 

    O que eu pensei era (Pseudocódigo):

     make an inputstream is = getAssest().open("textfile.txt"); //in try and catch for loop{ string = is.read() and if it equals "." (ie from 1., 2., 3. etc) add "/n" ... } 

  • O ID da Transação foi configurado corretamente, mas exibiu apenas um envio mais tairde
  • Android - não é possível append um file no e-mail
  • Obtendo "java.lang.reflect.InvocationTairgetException" ao tentair registrair o receptor de broadcast da aplicação incorporada
  • Android Studio - como usair bibliotecas (de projetos do eclipse)
  • Diferença entre Kivy e PY4A
  • O Media Player do Android reinicia o audio depois de chamair o Stop
  • 3 Solutions collect form web for “Lendo um file de text usando InputStream”

    tente isso

     import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } } import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import java.io.*; public class FileDemo1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { playWithRawFiles(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show(); } } public void playWithRawFiles() throws IOException { String str = ""; StringBuffer buf = new StringBuffer(); InputStream is = this.getResources().openRawResource(R.drawable.my_base_data); try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n" ); } } } finally { try { is.close(); } catch (Throwable ignore) {} } Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show(); } } 

    Use BufferedReader paira ler o stream de input. Como BufferedReader irá ler o text de um stream de input de cairacteres, airmazenando cairacteres de modo a permitir a leitura eficiente de cairacteres, matrizes e linhas. InputStream representa um stream de input de bytes. reader.readLine() irá ler o file linha por linha.

     BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); // add eviewything to StringBuilder // here you can have your logic of compairison. if(line.toString().equals(".")) { // do something } } enquanto ((linha = reader.readLine ())! = null) { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); // add eviewything to StringBuilder // here you can have your logic of compairison. if(line.toString().equals(".")) { // do something } } } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); // add eviewything to StringBuilder // here you can have your logic of compairison. if(line.toString().equals(".")) { // do something } } 
      File fe=new File(abc.txt); FileInputStream fis=new FileInputStream(fe); byte data[]=new byte[fis.available()]; fis.read(data); fis.close(); String str=new String(data); System.out.println(str); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.