make a file with some path

O

ojvm

Tanks in advance to all for the time of reading this.

Well i'm trying tho create a file in the hard drive, actually i'm using
the class FileWriter and BufferedWriter together. the code looks like
this.

FileWriter escrivearchivo = new FileWriter(nombreArchivo,true);
BufferedWriter escribebuffer = new BufferedWriter(escrivearchivo);
escribebuffer.write(String.valueOf(registros.getString(z)) + ",");
escribebuffer.newLine();
escribebuffer.flush();

so, this make a file but a don't now how to say in what path put it on.
that means the file is created in c:\windows\system32.

all this is runing in tomcat.
 
L

Lee Fesperman

ojvm said:
Tanks in advance to all for the time of reading this.

Well i'm trying tho create a file in the hard drive, actually i'm using
the class FileWriter and BufferedWriter together. the code looks like
this.

FileWriter escrivearchivo = new FileWriter(nombreArchivo,true);
BufferedWriter escribebuffer = new BufferedWriter(escrivearchivo);
escribebuffer.write(String.valueOf(registros.getString(z)) + ",");
escribebuffer.newLine();
escribebuffer.flush();

so, this make a file but a don't now how to say in what path put it on.
that means the file is created in c:\windows\system32.

You just need to add the path to the file name. Using java.io.File is the most
convenient way to do that (then pass it to the FileWriter constructor). Without a path,
it will be placed in current directory.
 
O

ojvm

yes, it worked fine. and the code now looks like this.


nombreArchivo = nombreArchivo + ".txt";
File file = new File("//machine1/encuesta/" + nombreArchivo);
FileWriter escrivearchivo = new FileWriter(file,true);
BufferedWriter escribebuffer = new BufferedWriter(escrivearchivo);
 
A

Andrew Thompson

File file = new File("//machine1/encuesta/" + nombreArchivo);

Better to use the form..

File file = new File("machine1", nombreArchivo);

...to ensure the file separator is correct for the platform.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top