【发布时间】:2016-11-24 15:54:42
【问题描述】:
我正在尝试使用 Xamarin Android 写入文件。 这是我的代码:
try
{
string r = (string)(DateFormat.Format("yyyy-MM-dd-hh-mm-ss", new Date()));
string logFileBaseName = "drLog." + r; pause();
mAccelLogFileWriter = new FileWriter(new File(STORAGE_DIR, logFileBaseName + ".accel.csv"));
mStepLogFileWriter = new FileWriter(new File(STORAGE_DIR, logFileBaseName + ".steps.csv"));
}
catch (IOException e)
{
Log.Error(TAG, "Creating and opening log files failed!", e);
e.PrintStackTrace();
throw new RuntimeException(e);
}
知道我定义了:
protected string STORAGE_DIR = SAMPLES_DIR + File.Separator + "dr";
protected static readonly string SAMPLES_DIR = Android.OS.Environment.ExternalStorageDirectory + File.Separator + "samples_exp";
问题是我在创建文件 mAccelLogFileWriter 时遇到此异常。 这个例外说:
Java.Lang.RuntimeException: java.io.FileNotFoundException: /storage/emulated/0/samples_exp/dr/drLog.2016-07-21-09-22-59.accel.csv: open failed: ENOENT (No such file or directory)
当我调试代码时,我发现例如:SAMPLES_DIR="/storage/emulated/0/samples_exp" 当我尝试获取外部存储目录(SD 卡)时。
你能告诉我我的代码有什么问题吗?
【问题讨论】:
标签: android xamarin filewriter