How to read a text file in Android studio when I have the path of that file
This Below one works for me… :)
- //Read File
- readButton.setOnClickListener(new View.OnClickListener(){
- @Override public void onClick(View arg0) {
- String filename=editTextFileName.getText().toString();
- StringBuffer stringBuffer = new StringBuffer();
- try {
- //Attaching BufferedReader to the FileInputStream by the help of
- InputStreamReader BufferedReader inputReader = new BufferedReader(new
- InputStreamReader(getContext().openFileInput(filename)));
- String inputString;
- //Reading data line by line and storing it into the stringbuffer
- while ((inputString = inputReader.readLine()) != null) {
- stringBuffer.append(inputString + "\n");
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(stringBuffer.toString().length() == 0){
- Toast.makeText(getContext(),"File not Available...!",
- Toast.LENGTH_LONG).show();
- return;
- }
- else {
- //Displaying data on the toast Toast.makeText(getContext(), stringBuffer.toString(),
- Toast.LENGTH_LONG).show();
- return;
- }
- }
- });
Articoli simili
- Cos'è il "Derek Zoolander Center for Kids Who Can't Read Good and Who Wanna Learn to Do Other Stuff Good Too"?
- How to read a DICOM image in Python
- Is there a way to get the current URL or path from within a Angular2 component? I'm currently using Angular2 rc6.
- Qual è la differenza tra UiPath Enterprise Edition e Ui Path Community Edition?