First of all - I love you all at Stackoverflow! Everyone is very helpful! Sadly when I go to answer questions they are all too advance for me :'(
I want to save the text file to a folder - but not an absolute folder for example I want to save it to
{class location}/text/out.txt
Because the program is being worked on different computers the location changes, so I can't put C:// ect
I also know I need to use doubt "\\" - but this didn't work in my attempts
public void writeFile (int ID, int n) {
try{
String Number = Integer.toString(n);
String CID = Integer.toString(ID);
FileWriter fstream = new FileWriter("//folder//out.txt",true); //this don't work
BufferedWriter out = new BufferedWriter(fstream);
out.write(Number+"\t"+CID);
out.newLine();
out.close();
}//catch statements etc
Try something like this: File file = new File("/some/absolute/path/myfile. ext"); OutputStream out = new FileOutputStream(file); // Write your data out. close();
File file = new File(dir, hash + ". txt"); The key here is the File(File parent, String child) constructor. It creates a file with the specified name under the provided parent directory (provided that directory exists, of course).
you can use getAbsolutePath() function:
FileWriter fstream = new FileWriter(new File(".").getAbsolutePath()+"//folder//out.txt",true);
and i sugest you to take a look at this thread
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With