What I’m trying to do is the following…
FileInputStream fIn;
try {
fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
BufferedReader br = new BufferedReader(isr);
isTrue = Boolean.parseBoolean(br.readLine());
Log.i("IN", "isTrue = " + isTrue);
}
But this is only going to work in the class that extends the Activity class within Android.
I have a “Settings” class which writes and reads the current games settings from a file, but this file has a lot of data I dont really want manipulated.
I was initially using a BufferedReader & BufferedWriter but I cannot set the data to Private which means anyone can just edit the file. With a OutputStreamWriter it is a little more secure at least
How do I get my excising “Settings” class (which has entirely static methods) to have access to the Context so I may use methods such as openFileInput
Create constructor for your Settings class that has Context argument. Then when you instantiate the object from that class, just pass the your application context, thats it.
Constructor:
In your activity class: