Pressure
Newbie
- Joined
- Jul 3, 2003
- Messages
- 5,065
- Reaction score
- 0
I can't for the life of me figure this out. No matter what I do I can't get Java to write information to a file. It's driving me crazy because I've done everything the book has told me to do and it still doesn't work. If you know Java could you look at this code and tell me what I'm doing wrong.
The MyConsoleIO is just a class I made for reading in information incase you were wondering. Can someone tell me what I'm doing wrong or at least show me a right way to do it?
Code:
import java.io.*;
import java.util.*;
public class test {
public static void main(String args[]) throws java.io.IOException {
// Get name of file to be written
System.out.print("Enter name of file to save: ");
String fileName = MyConsoleIO.getString();
// Open file, Layer with BufferedWriter and PrintWriter
FileWriter outfile = new FileWriter(fileName);
BufferedWriter bufWrite = new BufferedWriter(outfile);
PrintWriter output = new PrintWriter(bufWrite);
// Write to file
output.println("This is a test");
// Close file
outfile.close();
}
}
The MyConsoleIO is just a class I made for reading in information incase you were wondering. Can someone tell me what I'm doing wrong or at least show me a right way to do it?