-2
我想將文本追加到黑莓文本文件中,我該怎麼辦如何將文本追加到黑莓文本文件中
我想將文本追加到黑莓文本文件中,我該怎麼辦如何將文本追加到黑莓文本文件中
簽出此代碼。這基本上是將日誌寫入SD卡中的文件。您可以自定義您想要的方式。請享用。
static String pFilePath = "SDCard/BlackBerry/pictures/Log.txt";
public static void writeLog(String data) {
FileConnection fc = null;
OutputStream lStream = null;
Date d = new Date();
Calendar c = Calendar.getInstance();
String time = new String();
if (pFilePath != null) {
try {
fc = (FileConnection) Connector.open("file:///" + pFilePath,
Connector.READ_WRITE);
if (null == fc || fc.exists() == false) {
fc.create();
}
lStream = fc.openOutputStream(fc.fileSize());
c.setTime(d);
time = c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + ":" + c.get(Calendar.MILLISECOND);
data = "\n" + time + "("
+ (System.currentTimeMillis() - currentTimeMillies)
+ " ms)" + " -- " + data;
currentTimeMillies = System.currentTimeMillis();
lStream.write(data.getBytes());
} catch (Exception ioex) {
ioex.printStackTrace();
} finally {
if (lStream != null) {
try {
lStream.close();
lStream = null;
} catch (Exception ioex) {
}
}
if (fc != null) {
try {
fc.close();
fc = null;
} catch (Exception ioex) {
}
}
}
}
}
這是什麼意思?你想添加某種字符串到文本文件並將其保存在設備上? –