Ive finished an application and have tested all the functions and they are working. However one part of inputted data is supposed to be saved to a .txt file. Ive placed this inside a string but Im a bit out of my depth in this area and have no idea how to save this to a drive on my PC. Any help is appreciated. The code is on this link: http://sharetext.org/fSy2
Asked
Active
Viewed 859 times
-2
-
Check `FileOutputStream` , `BufferedWriter`, `FileWriter` – Java_User Mar 10 '14 at 12:22
-
And if you have Apache commons IO lib you can use `FileUtils.writeStringToFile()` – Java_User Mar 10 '14 at 12:22
-
@Java_User . I believe only FileWriter, BufferedWriter and File are sufficient. FileOutputStream is not necessary. – TheLostMind Mar 10 '14 at 12:22
-
Paste your piece of code please – ruhungry Mar 10 '14 at 12:25
1 Answers
0
Try This:
public static void main(String args[])throws IOException {
File file = new File("Hello1.txt");
// creates the file
file.createNewFile();
// creates a FileWriter Object
FileWriter writer = new FileWriter(file);
// Writes the content to the file
writer.write("This\n is\n an\n example\n");
writer.flush();
writer.close();
}
Read more abut here

Salah
- 8,567
- 3
- 26
- 43