how to change a java.io.File's path

hi everybody!!

i would like to set the path to a java.io.File, but I don't see any setter method.

I'm trying to save a file in a pre-defined directory (final static String path),

and I get the file I want to save from a jFileChooser. but, I don't know how i can change the path of the file to write it using this function:

private boolean writeFile (File fichero, String dataString) {

try {

PrintWriter out =new PrintWriter (new BufferedWriter (new FileWriter (file)));

out.print (dataString);

out.flush ();

out.close ();

}

catch (IOException e) {

return false;

}

return true;

}

In this function, dataString is writen in file. File's path has the path that the file will be saved.

Can somebody help me?

Thanks,

[833 byte] By [sweeea] at [2007-11-27 9:37:51]
# 1

You have to create a new file object containing the name from the original file object with the path you want. Or you can write it, and then rename it with the complete path (which will move it, but also needs a new File object, as above).

So, if the file doesn't already exist, simply create a new file object. If the original file object is still needed outside of the method, then write it, create a new File object, and "rename" the original file object using the new file object.

masijade.a at 2007-7-12 23:10:02 > top of Java-index,Java Essentials,Java Programming...
# 2

hi masijade,

thanks for your response. I understand what you say theorically, but I don't know how to do in practice. if I have a new file with the path i want, and in the other hand i have the file that has the content that i want to save, how can I do to copy the content to the other file?

thanks

sweeea at 2007-7-12 23:10:02 > top of Java-index,Java Essentials,Java Programming...
# 3
Sorry! Forget my last post, please. It was a fool question.Thanks for the help.Regards
sweeea at 2007-7-12 23:10:02 > top of Java-index,Java Essentials,Java Programming...