내부 스토리지 (안드로이드)에 파일로 :저장 객체 내가이 시도
public class People implements Serializable {
String name;
public People(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void saveAsObject(People p) throws FileNotFoundException, IOException
{
try
{
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(new File("test","test.dat")));
os.writeObject(p);
os.close();
System.out.println("Sucess");
}
catch(IOException e)
{
System.out.println(e);
}
}
}
내가 수동으로 폴더를 만들었습니다. 내가 그것을 java.io를 던졌습니다
new FileOutputStream("text.dat")
시도 (해당 파일 또는 디렉터리)
"ENOENT java.io.FileNotFoundException : /test/test.txt : 개방 실패"그것은이 eror을 던졌습니다 .FileNotFoundException : EROFS (전용 파일 시스템을 읽기)
이 내 메인 클래스입니다 :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
People p = new People("Ray");
try {
p.saveAsObject(p);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
이것을 시도하십시오 : http://stackoverflow.com/a/15067968/1531054 –
고맙습니다. Context.getFilesDir()을 시도해 보겠습니다. – n0hepe