我將創建一個檔案夾來保存我的檔案 png。檔案夾名稱以當天為準。我試圖將“day” “/”放在 outputstream 中但不作業,這就是非法分隔符。
這是我的代碼:
try {
Date c = Calendar.getInstance().getTime();
System.out.println("Current time => " c);
SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy", Locale.getDefault());
SimpleDateFormat dforario = new SimpleDateFormat("HH_mm_ss", Locale.getDefault());
String nomeFile = df.format(c) "/" tavolaScelta "_rotazione_parte_" i "_" dforario.format(c) ".png";
FileOutputStream fileOutputStream = openFileOutput(nomeFile, Context.MODE_PRIVATE);
frameLayoutBitmapped.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
我期望的結果是:
08_03_2022(這是每天的目錄)---> R1_R1_rotazione_parte_1_16_23.png(這是影像檔案)
謝謝你的幫助。
uj5u.com熱心網友回復:
字串 nomeFile = df.format(c) "/" tavolaScelta " rotazione_parte " i "_" dforario.format(c) ".png";
檔案的名稱應該只是一個名稱。
所以它不能包含/字符。
如果您使用openFileOutput()該檔案將只登陸getFilesDir().
如果您想在 getFilesDir() 中創建自己的子目錄,則首先使用 mkdirs() 創建它們,然后使用new FileOutputStream()在其中創建檔案。
File dir = new File(getFilesDir(), "myfolder/yetafolder");
if ( ! dir.exists() )
if ( !dir.mkdirs())
return;
File file = new File (dir, "myfilename.png");
FileOutputStream fos = new FileOutputStream(file);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/441144.html
下一篇:特定查詢字串的重寫規則
