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.
java
|
show 2 more comments
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.
java
You don't have andhomefolder in your project
– XtremeBaumer
Nov 19 at 14:06
Are you on Windows or Linux? On Windows, you would be specifying a folderhomewhich is relative to your project. On Linux, that might meanhome, a folder relative to root.
– Tim Biegeleisen
Nov 19 at 14:07
/homeindicates 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
|
show 2 more comments
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.
java
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
java
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 andhomefolder in your project
– XtremeBaumer
Nov 19 at 14:06
Are you on Windows or Linux? On Windows, you would be specifying a folderhomewhich is relative to your project. On Linux, that might meanhome, a folder relative to root.
– Tim Biegeleisen
Nov 19 at 14:07
/homeindicates 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
|
show 2 more comments
You don't have andhomefolder in your project
– XtremeBaumer
Nov 19 at 14:06
Are you on Windows or Linux? On Windows, you would be specifying a folderhomewhich is relative to your project. On Linux, that might meanhome, a folder relative to root.
– Tim Biegeleisen
Nov 19 at 14:07
/homeindicates 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
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You don't have and
homefolder in your project– XtremeBaumer
Nov 19 at 14:06
Are you on Windows or Linux? On Windows, you would be specifying a folder
homewhich is relative to your project. On Linux, that might meanhome, a folder relative to root.– Tim Biegeleisen
Nov 19 at 14:07
/homeindicates 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