简体   繁体   English

如何将对象写入原始文件夹文件

[英]How can I write an Object to my raw folder file

This is my serializable class. 这是我的可序列化的类。

public class Person implements Serializable{
private String name;
private String surname;
private int age;


public Person(String name,String surname,int age){
    this.name = name;
    this.surname = surname;
    this.age = age;
}

public void setSurname(String surname) {

    this.surname = surname;
}

public void setName(String name) {
    this.name = name;
}
public void setAge(int age){
    this.age = age;
}

public int getAge() {
    return age;
}

public String getName() {
    return name;
}

public String getSurname() {
    return surname;
}
public String toString(){
return name + " "+surname+" "+age;
}
}

I am trying to write a Person class to a raw folder using FileOutputStream, but nothing is working. 我正在尝试使用FileOutputStream将Person类写入原始文件夹,但是没有任何反应。 Can't create a FileOutputStream, to get the raw folder file. 无法创建FileOutputStream来获取原始文件夹文件。

Also I tried a FileOutputStream. 我也尝试了FileOutputStream。

 FileOutputStream fos = getBaseContext().openFileOutput(
     "android.resource://com.cpt.sample/raw/text.txt",MODE_PRIVATE);

You can't change resource file. 您无法更改资源文件。 They are static at run-time. 它们在运行时是静态的。 you can check here . 你可以在这里查看

And to put file at runtime you can use : 要在运行时放置文件,您可以使用:

  • internal storage (or) 内部存储(或)
  • external storage 外置储存

and to get this directories use : Environment.getExternalFilesDir() 并获取此目录,请使用: Environment.getExternalFilesDir()

Fore more information go here . 有关更多信息,请转到此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM