我需要在Java中使用ororid創建新文件。我不喜歡這樣寫道:在android中設置新文件名的奇怪行爲
public static File getAbosoluteFile(String relativePath, Context context) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return new File(context.getExternalFilesDir(null), "AE " +".jpg");
} else {
Toast.makeText(context, "internal", Toast.LENGTH_SHORT).show();
return new File(context.getFilesDir(), "AE" +".jpg");
}
}
但是當我把它像這樣 - 它工作正常,但是當我使用字符串從方法更改名稱,例如:
public static String getCurrentDate()
{
String returnDate = null;
Calendar currentDate = Calendar.getInstance();
int minute = currentDate.get(Calendar.MINUTE);
String editedMinute;
if (minute<10)
editedMinute = "0" + Integer.toString(minute);
else
editedMinute = Integer.toString(minute);
returnDate= (Integer.toString((currentDate.get(Calendar.MONTH) + 1)) + "/" +Integer.toString(currentDate.get(Calendar.DAY_OF_MONTH)) + "/" +Integer.toString(currentDate.get(Calendar.YEAR)) + " " +
Integer.toString(currentDate.get(Calendar.HOUR_OF_DAY)) + ":" + editedMinute);
return returnDate;
}
因此,即使,當我使用return new File(context.getExternalFilesDir(null), "12/12/12 " +".jpg");
該文件是不會創建。我試圖在名稱中使用篩選 - 思想原因在於此,但結果相同。 Java的new File(File dir, String name)
是如此依賴於名稱格式?或者是什麼原因?
我什麼也不懂 –
在文件路徑中不能有「:」。還有其他人物也被禁止。 LogCat會告訴你!你可以使用「/」,但是你引入了子目錄。 – greenapps
爲什麼濫用?我添加了描述。 –