誰能告訴我爲什麼我的下面的代碼不起作用?我試圖追加一個字符串到文本/ html文件的內容。我只是跟着在Android開發文檔代碼hereAndroid:寫入文件不能正常工作
package com.example.GetContentThenAppend;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
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);
try {
String FILENAME = Environment.getExternalStorageDirectory() + "/EngagiaDroid/videos.html";
String string = "<div style='color: blue; border: thin solid red;'>YO!</div>";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_APPEND);
fos.write(string.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
錯誤是什麼?你怎麼知道它不工作? – Haphazard 2011-05-20 17:14:35
感謝您的回覆,當我運行此代碼時,我收到強制關閉消息... – Kris 2011-05-20 17:18:13
請查看logcat以獲取錯誤消息。 http://developer.android.com/guide/developing/tools/logcat.html – Haphazard 2011-05-20 17:18:59