Casa > H > How To Read A Text File In Android Studio When I Have The Path Of That File

How to read a text file in Android studio when I have the path of that file

This Below one works for me… :)

  1. //Read File 
  2. readButton.setOnClickListener(new View.OnClickListener(){ 
  3.  
  4. @Override public void onClick(View arg0) { 
  5. String filename=editTextFileName.getText().toString(); 
  6.  
  7. StringBuffer stringBuffer = new StringBuffer(); 
  8. try { 
  9. //Attaching BufferedReader to the FileInputStream by the help of  
  10. InputStreamReader BufferedReader inputReader = new BufferedReader(new  
  11. InputStreamReader(getContext().openFileInput(filename))); 
  12. String inputString; 
  13.  
  14. //Reading data line by line and storing it into the stringbuffer  
  15.  
  16. while ((inputString = inputReader.readLine()) != null) { 
  17. stringBuffer.append(inputString + "\n"); 
  18.  
  19. } catch (IOException e) { 
  20. e.printStackTrace(); 
  21. if(stringBuffer.toString().length() == 0){ 
  22. Toast.makeText(getContext(),"File not Available...!", 
  23. Toast.LENGTH_LONG).show(); 
  24. return; 
  25.  
  26. else { 
  27. //Displaying data on the toast Toast.makeText(getContext(), stringBuffer.toString(), 
  28. Toast.LENGTH_LONG).show(); 
  29. return; 
  30. }); 

De Ferdinand Binkerd

Posso assistir ao eclipse solar colocando meu telefone em um fone de ouvido VR e ter a câmera funcionando com o fone de ouvido? :: Qual é a sua opinião sobre o conjunto VR do Mi?