0
我正在嘗試使用時間戳作爲名稱保存文件。當我自己命名文件時,我可以保存文件沒有問題,但是當我嘗試使用時間戳時,它不起作用。這是我的代碼:使用時間戳保存文件
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
File newxmlfile = new File(Environment.getExternalStorageDirectory()
+ ts);
try {
newxmlfile.createNewFile();
} catch (IOException e) {
Log.e("IOException", "exception in createNewFile() method");
}
FileOutputStream fileos = null;
try {
fileos = new FileOutputStream(newxmlfile);
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException", "can't create FileOutputStream");
}
有沒有人知道如何做到這一點?
編輯(求助):我改變了下面的行,它使用時間戳保存文件作爲一個XML文件。
File newxmlfile = new File(Environment.getExternalStorageDirectory()
,ts + ".xml");
你得到了哪個錯誤? – 2013-03-06 14:02:00
-1不定義「不起作用」 – njzk2 2013-03-06 14:02:50