我试图在我的应用程序运行时将数据存储在一个文件中,以便在我将其连接到 PC 时轻松地将其从设备中取出。
现在,我可以创建文件并写入文件,但我的计算机看不到该文件。
请注意,我真的不想使用 DDMS,因为我会要求经验有限的人这样做。
我知道它正在写入文件,因为我可以在设备的文件管理器上看到它。如果我将文件复制到设备上的另一个目录中,然后我可以在计算机上看到它,但这对于我的情况来说不是一个有效的解决方法。
这是我所拥有的:
String fileName = "test";
String stuffToWrite = "testString";
try
{
File sdCard = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File dir = new File (sdCard.getAbsolutePath());
dir.mkdirs();
File file = new File(dir, fileName + ".csv");
file.setReadable(true,false);
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
// Write the string to the file
osw.write(stuffToWrite);
/* ensure that everything is
* really written out and close */
osw.flush();
osw.close();
}
感谢您的时间。