1

I'm developing an app for android, and I need to write data to a text file to read later in other activities. Here is my body of the code in question.

        //writes the string "hello android" to file
        FileOutputStream outFile = openFileOutput("myfile.txt", MODE_WORLD_READABLE);
        OutputStreamWriter osw = new OutputStreamWriter(outFile);
        String hello = "hello android.";
        osw.write(hello);
        osw.flush();
        osw.close();

When I first wrote this code, I was given a warning, so I added the line

@SuppressWarnings("deprecation")

to the top of my function. However, MODE_WORLD_READABLE is still crossed out in my IDE. Why? Note: the function has try-catch statements where they should be, and a "throws IOException at the top of the function.

DeepDeadpool
  • 1,441
  • 12
  • 36
  • 1
    possible duplicate [Android: Alternative to the deprecated Context.MODE_WORLD_READABLE?](http://stackoverflow.com/questions/13856757/android-alternative-to-the-deprecated-context-mode-world-readable) – Reimeus Feb 16 '14 at 22:28
  • Eclipse has such glitches. Try restarting the IDE. – B.J. Smegma Feb 16 '14 at 22:29
  • [This blog post](http://www.devlog.en.alt-area.org/?p=697) has some instructions for removing the strikethrough, though I have not tried it and cannot vouch for whether it works. – CommonsWare Feb 16 '14 at 22:32

2 Answers2

6

The annotation @SuppressWarnings("deprecation") will suppress the warning (you will have no more yellow underline). However it will not suppress the fact that the element you are using is still deprecated and will leave it striked through.

Melquiades
  • 8,496
  • 1
  • 31
  • 46
TheCopycat
  • 401
  • 2
  • 6
  • And I wouldn't have it any other way. The strikethrough does no harm, but it does warn you or anyone else reading your code that deprecated code is being used. – Reinstate Monica Feb 16 '14 at 23:01
0

Eclipse knows that MODE_WORLD_READABLE is deprecated. This mean that, although you can still use it, the developers of the Android SDK recommend against it. @SuppressWarnings("deprecation") says to supress the warning, but you are still using a deprecated element.
For the reason why it was deprecated see http://developer.android.com/reference/android/content/Context.html#MODE_WORLD_READABLE.

McLovin
  • 3,554
  • 1
  • 14
  • 15