//Read in. st. from File"screenoff"
String fileName = "screenoff";
int readed;
String content="";
byte[] buff = new byte[256]; //input stream buffer
//Input stream
try{
FileInputStream reader = context.getApplicationContext().openFileInput(fileName);
while((readed = reader.read(buff))!=-1){
content+=new String(buff).trim();
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
//End of Read in. st. from File"screenoff"
----------------------------------------------------------------------------------------------------
Instead of
openFileInput("string.txt");
try usingcontext.getApplicationContext().openFileInput("string.txt");
.
沒有留言:
張貼留言