2

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?

4

1 回答 1

2

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.

于 2012-04-24T11:24:03.673 回答