This is probably a silly question, but I'm pretty new to Java and I can't figure it out.
 Basically, I'm trying to download some files from a website and I want to save them to a particular folder (rather than the default of the same folder that my Java file is located in). How can I do this?
I've been using FileReader, BufferedReader, BufferedInputStream, and FileOutputStream classes.
Thanks :)
Java is pretty friendly with IO. Try something like this:
File file = new File("/some/absolute/path/myfile.ext");
OutputStream out = new FileOutputStream(file);
// Write your data
out.close();
Notes:
/, it will be relative to your "current" directoryBufferedWriter easier: BufferedWriter writer = new BufferedWriter(new FileWriter(file));. It has newLine() and write(String) methodsWhen you insantiate your FileOutputStream you can pass an absolute path to the constructor. Like this:
FileOutputStream os = new FileOutputStream("/path/to/file.txt");
                        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