필자는 파일에서 개체를 직접 읽고 쓸 수있는 일종의 직렬화를 시도하고 있습니다.자바 안드로이드에서 EOFException이 발생합니까? 도움이 필요
시작하려면 문자 하나를 파일에 쓰려고 시도하고 읽으려고했습니다. 이것은 나를 항상 EOF
예외를주는 유지합니다.
Android 기기에서 사용하려고합니다. 여기 내 코드입니다 :
public class TestAppActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
WriteToFile();
Load();
} catch (Exception e) {
e.printStackTrace();
}
}
public void Load() throws IOException
{
InputStream fis;
ObjectInputStream in = null;
try {
fis = new FileInputStream(Environment.getExternalStorageDirectory() + "\\test2.ser");
in = new ObjectInputStream(fis);
char temp = in.readChar();
} catch (IOException e) {
e.printStackTrace();
} finally {
in.close();
}
}
public static void WriteToFile() throws Exception {
try {
OutputStream file = new FileOutputStream(Environment.getExternalStorageDirectory() + "\\test2.ser");
ObjectOutput output = new ObjectOutputStream(file);
try {
output.writeChar('c');
} finally {
output.close();
}
} catch (IOException ex) {
throw ex;
}catch (Exception ex) {
throw ex;
}
}
}
'WriteToFile'기능이 제대로 작동하는지 확인 했습니까? –
EOFException에서 추적을 표시하십시오. 어떤 줄에서 예외가 발생 했습니까? –