【发布时间】:2016-11-22 21:01:27
【问题描述】:
我正在尝试将数据写入文件并将其存储在数据库中。我在网上尝试了很多代码。但是,我无法写入数据。谁能帮帮我。截至目前,我正在使用以下代码。我声明了 onClick="writemessage" 并在 writemessage(View view) 函数中使用了以下代码。我通过将手机连接到笔记本电脑来运行。谁能帮帮我。
FileOutputStream fos = null;
try {
String filename = "abc.txt";
String data = "Sensor data is found";
File myFile = new File(Environment
.getExternalStorageDirectory(), filename);
if (!myFile.exists())
myFile.createNewFile();
byte[] data = string.getBytes();
try {
fos = new FileOutputStream(myFile);
fos.write(data);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
【问题讨论】:
-
请详细解释“我无法写入数据”是什么意思。
-
欢迎来到 Stack Overflow!请查看我们的SO Question Checklist 以帮助您提出一个好问题,从而得到一个好的答案。
标签: java android database memory android-sdcard