日期:2014-05-20  浏览次数:20711 次

请教各位j2me中读写文件的问题

try{
                        InputStream   inputStream   =   this.getClass().getResourceAsStream( "iconname.txt ");
                        stringBuffer   =   new   StringBuffer();
                       
                        int   input;
                        while   ((input   =   inputStream.read())   !=   -1){
                                if   (input   !=   '\n '){
                                        stringBuffer.append((char)input);
                                }else{
                                        iconNameVector.addElement(stringBuffer.toString());
                                        stringBuffer   =   new   StringBuffer();
                                }  
                        }
                        inputStream.close();
                        connect.close();
                       
                }catch(Exception   ex){
                        System.out.println( "the   file   connection   could   not   be   established ");
                }

这种情况下会出现错误java.lang.NullPointerException

                try{
                        connect   =   (StreamConnection)Connector.open( "http://localhost:8080/iconname.txt ",   Connector.READ);
                        inputStream   =   connect.openInputStream();
                       
                        stringBuffer   =   new   StringBuffer();
                       
                        int   input;
                        while   ((input   =   inputStream.read())   !=   -1){
                                if   (input   !=   '\n '){