Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Read text file from SD card

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 81
    Comment on it

    Below is the code to read a text file from SD card.

    First, we have to define path of the text file to a File.

    Second step is to use BufferedReader class to read line by line.

    File sdcard = Environment.getExternalStorageDirectory();
    
    
    File readFile = new File(sdcard,"reading.txt");
    
    //Read text from file
    StringBuilder stringBuilder = new StringBuilder();
    
    try {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(readFile));
        String str;
    
        while ((str = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append('\n');
        }
        bufferedReader.close();
    }
    catch (IOException e) {
        System.out.println("Error : "+e.getMessage());
    }
    
    TextView messageFile = (TextView)findViewById(R.id.message_text);
    
    messageFile.setText(text.toString());
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: