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.

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top