问题描述
我有在玻璃上运行的应用程序。我想我的应用程序在运行时创建文件和能够写/从这些文件中读取数据到/。谁能告诉我一个办法做到这一点?难道Android的openFileOutput()玻璃工作?
I have an application that runs on glass. I want my application to create files at run time and be able to write/read data to/from those files. Can anyone show me a way to do this? Does Android's openFileOutput() work in glass?
推荐答案
(在情况下,如果任何人有同样的问题)
(In case if anyone else has the same question)
好吧,我想出了一个办法做到这一点。它看起来像Java I / O库正常工作与Android和也为玻璃。下面玻璃工作正常。
Okay I figured out a way to do this. It looks like Java i/o libraries works fine with android and also for glass. The following works fine in glass.
字符串文件名=sensorData;
FileOutputStream中的OutputStream;
String filename = "sensorData"; FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_APPEND);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter (outputStream);
outputStreamWriter.write(content);
outputStreamWriter.close();
}
catch (Exception e) {
e.printStackTrace();
}
//Printing the file in logcat just to verify the contents
FileInputStream inputStream;
try
{
inputStream = openFileInput(filename);
InputStreamReader inputStreamReader = new InputStreamReader (inputStream);
char[] buffer = new char[content.length()];
inputStreamReader.read(buffer);
String input = buffer.toString();
Log.i(input);
}
catch (Exception e)
{
e.printStackTrace();
}
这篇关于如何创建从谷歌玻璃应用程序的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!