파일을로드하고 저장하기 위해 내 Activity 클래스 내에있는 코드가 있습니다. 그것은 잘 작동합니다. 이 코드는 cFavretClass의 내용을 저장합니다. 나는 코드를 정리하려고하는데, 그래서 파일을 i/o를 cFavret 클래스로 옮겼다.Activity 클래스 내에 파일 I/O가 있어야합니까?
컴파일 할 코드를 가져올 수 없습니다. 이제 openFileOutput is undefined in type cFavrets
이라는 오류 메시지가 나타납니다.
나는이 방법이 Googles Activity Class에 선언되었다고 가정하고 있습니까? 모든 파일 입출력이 활동 클래스에 있어야 함을 의미합니까?
boolean Save()
{
String FILENAME = "hello_file";
try {
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(buffer);
fos.close();
}
// just catch all exceptions and return false
catch (Throwable t) {
return false;
}
return true;
}
boolean Load()
{
String FILENAME = "hello_file";
try {
FileInputStream fos = openFileInput(FILENAME);
buffer[0]=0;
fos.read(buffer);
fos.close();
}
// just catch all exceptions and return false
catch (Throwable t) {
// maybe file does not exist, try creating it
return false;
}
return true;
}
안녕하세요, Activty 클래스에서 어떻게 컨텍스트를 얻을 수 있습니까 ??? 나는 Context mContext를 시도하고있다. mContext = 컨텍스트. 작동하지 않음 –
활동은 컨텍스트입니다. 단지'this'를 전달하십시오. – JRaymond