0

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?

Prisoner
  • 49,922
  • 7
  • 53
  • 105
Kshitij
  • 61
  • 2

1 Answers1

1

(In case if anyone else has the same question)

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.

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();
        }
Kshitij
  • 61
  • 2