-3

I have a text file inside asset folder.I am trying to read it using Buffered reader as chars But I am stuck .Can you please help.

    InputStream in=assetManager.open("readme.txt");
        BufferedReader bf=new BufferedReader(new InputStreamReader(in));
        int x;
        String s="";

        while((s=bf.readLine())!=null){
            Character.to



        }
  • It looks like incomplete code for me. Can you post the entire code?. BTW where is the exception trace. – Stunner May 02 '14 at 11:45
  • Could you elaborate on what your problem is? Also, do you really NEED to use BufferedReader? I find Scanner to be easier to use. – kviiri May 02 '14 at 11:46
  • Side note: `String s="";` initialization not needed here. – Joffrey May 02 '14 at 11:48
  • please post complete code as this does code does not make sense. although because your question kind of makes sense so not down-voting or flagging. – madteapot May 02 '14 at 12:04

3 Answers3

0

Use

char[] ch = s.toCharArray();

if you want to get the string as character array.

Lallu Anthoor
  • 231
  • 1
  • 5
  • 1
    I don't understand why this is the accepted answer. It is not answering what the question seemed to be... oO Well if it helped the OP, then fine ^^ – Joffrey May 02 '14 at 12:57
0

Try like below

String txt= null;
        try {
            InputStream is = getAssets().open("readme.txt");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            txt= new String(buffer, "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
0
BufferedReader bf = null;
        try {
            InputStreamReader in= new InputStreamReader(assetManager.open("readme.txt");
            bf=new BufferedReader(in);
            String s="";
            s = bf.readLine();
            while (s != null) {
                s = bf.readLine(); 
            }
        } 
        catch (IOException e) {
        } 
        finally {
            if (bf != null) {
                bf.close();
            }
        }

This is the complete code, written from the point where @user3468916 left.

Arun George
  • 18,352
  • 4
  • 28
  • 28