开发者

Android: Appending string - getting force close message

Can someone tell me what is wrong with my code below?

public class GetContentThenAppend extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView tv2;
        tv2 = (TextView) this.findViewById(R.id.thetext);
        tv2.setText("This is the writing program...\n");
        
        try{
                /*
               File f = new File(Environment.getExternalStorageDirectory()+"/EngagiaDroid/videos.html");
               FileInputStream fileIS = new FileInputStream(f);
               BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
               String readString = new String();
             
               //just reading each line and pass it on the debugger
               int x = 1;
               while((readString = buf.readLine())!= null){
                   tv2.append( Integer.toString(x) + ":> " );
                   tv2.append( readString );
                   tv2.append( "\n" );
                   x++;
               }
                */
            
            final String entryString = new String("" +
                    "<div stle='color: red; border: this solid开发者_如何学Go red;'>" +
                    "Hey yo this is the new content!!!" +
                    "</div>" +
                    "</div>" +
                    "</div>" +
                    "</body>" +
                    "</html>");
            
            String htmlFile = Environment.getExternalStorageDirectory()+"/EngagiaDroid/videos.html";
            FileOutputStream fOut = openFileOutput(htmlFile, MODE_APPEND);
            OutputStreamWriter osw = new OutputStreamWriter(fOut);  

            osw.write(entryString);

            osw.flush();
            osw.close();
               
               
            } catch (FileNotFoundException e) {
               e.printStackTrace();
            } catch (IOException e){
               e.printStackTrace();
            }
    }
}

I am trying to update the html content by appending some string/html code to it. I am getting a force close message when I try to run it.


I end up using another method. I used the ff code:

    String TESTSTRING = "<div style='color: blue; border: thin solid red;'>YO!</div>";

    File root = Environment.getExternalStorageDirectory();
    if (root.canWrite()){
        File gpxfile = new File(root, "samplefile.html");
        FileWriter gpxwriter = new FileWriter(gpxfile, true);
        BufferedWriter out = new BufferedWriter(gpxwriter);
        out.write(TESTSTRING);
        out.close();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜