Search code examples
javajava-mebufferedreader

J2ME alternative for java.io.BufferedReader?


I got a code from net and it uses

imports java.io.BufferedReader 
imports java.io.PrintWriter 

This code is in JAVA SE. But I need to do the same in J2ME(JAVA ME). But it doesn't have BufferedReader and PrintWriter?

What can be used instead of BufferedReader and PrintWriter?


Solution

  • If BufferedReader is there because of readLine method you can replace it by InputStreamReader and use a method like:

    
        public String readLine(Reader reader) throws IOException {
            StringBuffer line = new StringBuffer();
            int c = reader.read();
    
            while (c != -1 && c != '\n') {
                line.append((char)c);
                c = reader.read();
            }
    
            if (line.length() == 0 && c == -1) {
                return null;
            }
    
            return line.toString();
        }
    
    

    If PrintWriter is there because of print methods you can replace it by PrintStream.