FileNotFoundException when saving to a file











up vote
-2
down vote

favorite












I am trying to create a program that saves an array to a file but it doesn't work:



File archivo = new File("/home");
static ArrayList<Contacto> contactos = new ArrayList<Contacto>();

static void leerFichContactos(File archivo) throws IOException, ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(archivo);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
contactos = (ArrayList<Contacto>)objectIn.readObject();
objectIn.close();

ObjectInputStream leyendoFichero = new ObjectInputStream(new FileInputStream("contactos.dat") );
contactos = (ArrayList <Contacto> )leyendoFichero.readObject();
leyendoFichero.close();
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
static void escribirDatosContactos(File archivo) throws IOException {
// check if sd card is mounted and available for read & write
try {
// create a file in downloads directory
FileOutputStream fos =
new FileOutputStream(archivo);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(contactos);
os.close();
Log.v("MyApp","El archivo ha sido guardado");
} catch (Exception ex) {
Log.e("Ficheros","Error al escribir el fichero en la memoria interna");
}
}


It returns this error



java.io.FileNotFoundException: /home (No such file or directory)


It may have something to do with the fact that I create a new activity on Android when I try to upload the file, but I'm not sure.










share|improve this question
























  • You don't have and home folder in your project
    – XtremeBaumer
    Nov 19 at 14:06










  • Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
    – Tim Biegeleisen
    Nov 19 at 14:07










  • /home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
    – Thomas
    Nov 19 at 14:08












  • Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
    – GhostCat
    Nov 19 at 14:08










  • i'm using windows, Can you give me a correct path for this case?
    – victor96
    Nov 19 at 14:10















up vote
-2
down vote

favorite












I am trying to create a program that saves an array to a file but it doesn't work:



File archivo = new File("/home");
static ArrayList<Contacto> contactos = new ArrayList<Contacto>();

static void leerFichContactos(File archivo) throws IOException, ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(archivo);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
contactos = (ArrayList<Contacto>)objectIn.readObject();
objectIn.close();

ObjectInputStream leyendoFichero = new ObjectInputStream(new FileInputStream("contactos.dat") );
contactos = (ArrayList <Contacto> )leyendoFichero.readObject();
leyendoFichero.close();
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
static void escribirDatosContactos(File archivo) throws IOException {
// check if sd card is mounted and available for read & write
try {
// create a file in downloads directory
FileOutputStream fos =
new FileOutputStream(archivo);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(contactos);
os.close();
Log.v("MyApp","El archivo ha sido guardado");
} catch (Exception ex) {
Log.e("Ficheros","Error al escribir el fichero en la memoria interna");
}
}


It returns this error



java.io.FileNotFoundException: /home (No such file or directory)


It may have something to do with the fact that I create a new activity on Android when I try to upload the file, but I'm not sure.










share|improve this question
























  • You don't have and home folder in your project
    – XtremeBaumer
    Nov 19 at 14:06










  • Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
    – Tim Biegeleisen
    Nov 19 at 14:07










  • /home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
    – Thomas
    Nov 19 at 14:08












  • Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
    – GhostCat
    Nov 19 at 14:08










  • i'm using windows, Can you give me a correct path for this case?
    – victor96
    Nov 19 at 14:10













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I am trying to create a program that saves an array to a file but it doesn't work:



File archivo = new File("/home");
static ArrayList<Contacto> contactos = new ArrayList<Contacto>();

static void leerFichContactos(File archivo) throws IOException, ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(archivo);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
contactos = (ArrayList<Contacto>)objectIn.readObject();
objectIn.close();

ObjectInputStream leyendoFichero = new ObjectInputStream(new FileInputStream("contactos.dat") );
contactos = (ArrayList <Contacto> )leyendoFichero.readObject();
leyendoFichero.close();
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
static void escribirDatosContactos(File archivo) throws IOException {
// check if sd card is mounted and available for read & write
try {
// create a file in downloads directory
FileOutputStream fos =
new FileOutputStream(archivo);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(contactos);
os.close();
Log.v("MyApp","El archivo ha sido guardado");
} catch (Exception ex) {
Log.e("Ficheros","Error al escribir el fichero en la memoria interna");
}
}


It returns this error



java.io.FileNotFoundException: /home (No such file or directory)


It may have something to do with the fact that I create a new activity on Android when I try to upload the file, but I'm not sure.










share|improve this question















I am trying to create a program that saves an array to a file but it doesn't work:



File archivo = new File("/home");
static ArrayList<Contacto> contactos = new ArrayList<Contacto>();

static void leerFichContactos(File archivo) throws IOException, ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(archivo);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
contactos = (ArrayList<Contacto>)objectIn.readObject();
objectIn.close();

ObjectInputStream leyendoFichero = new ObjectInputStream(new FileInputStream("contactos.dat") );
contactos = (ArrayList <Contacto> )leyendoFichero.readObject();
leyendoFichero.close();
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
static void escribirDatosContactos(File archivo) throws IOException {
// check if sd card is mounted and available for read & write
try {
// create a file in downloads directory
FileOutputStream fos =
new FileOutputStream(archivo);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(contactos);
os.close();
Log.v("MyApp","El archivo ha sido guardado");
} catch (Exception ex) {
Log.e("Ficheros","Error al escribir el fichero en la memoria interna");
}
}


It returns this error



java.io.FileNotFoundException: /home (No such file or directory)


It may have something to do with the fact that I create a new activity on Android when I try to upload the file, but I'm not sure.







java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 15:03









Mihai Chelaru

2,10071022




2,10071022










asked Nov 19 at 14:06









victor96

11




11












  • You don't have and home folder in your project
    – XtremeBaumer
    Nov 19 at 14:06










  • Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
    – Tim Biegeleisen
    Nov 19 at 14:07










  • /home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
    – Thomas
    Nov 19 at 14:08












  • Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
    – GhostCat
    Nov 19 at 14:08










  • i'm using windows, Can you give me a correct path for this case?
    – victor96
    Nov 19 at 14:10


















  • You don't have and home folder in your project
    – XtremeBaumer
    Nov 19 at 14:06










  • Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
    – Tim Biegeleisen
    Nov 19 at 14:07










  • /home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
    – Thomas
    Nov 19 at 14:08












  • Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
    – GhostCat
    Nov 19 at 14:08










  • i'm using windows, Can you give me a correct path for this case?
    – victor96
    Nov 19 at 14:10
















You don't have and home folder in your project
– XtremeBaumer
Nov 19 at 14:06




You don't have and home folder in your project
– XtremeBaumer
Nov 19 at 14:06












Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
– Tim Biegeleisen
Nov 19 at 14:07




Are you on Windows or Linux? On Windows, you would be specifying a folder home which is relative to your project. On Linux, that might mean home, a folder relative to root.
– Tim Biegeleisen
Nov 19 at 14:07












/home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
– Thomas
Nov 19 at 14:08






/home indicates you're on Linux. In that case this would be a directory, i.e. you can't read any data from it anyways.
– Thomas
Nov 19 at 14:08














Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
– GhostCat
Nov 19 at 14:08




Honestly: try to come up with a real Minimal, Complete, and Verifiable example. Avoid code that uses other languages than English. That just reduces your chances of getting good answers.
– GhostCat
Nov 19 at 14:08












i'm using windows, Can you give me a correct path for this case?
– victor96
Nov 19 at 14:10




i'm using windows, Can you give me a correct path for this case?
– victor96
Nov 19 at 14:10

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376375%2ffilenotfoundexception-when-saving-to-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376375%2ffilenotfoundexception-when-saving-to-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno