Android: добавление строки не работает - PullRequest
0 голосов
/ 20 мая 2011

Может кто-нибудь сказать мне, что не так с моим кодом ниже? Я новичок в Java и Android Dev, большое спасибо в продвинутом! :)

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 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();
            }
    }
}

Я пытаюсь обновить содержимое html, добавив к нему какой-либо строковый / html-код. я получаю сообщение о принудительном закрытии, когда пытаюсь его запустить.

1 Ответ

0 голосов
/ 21 мая 2011

В итоге я использую другой метод.Я использовал код FF:

    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();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...