Results 1 to 10 of 10
Thread: Help with printwriter class
- 09-19-2010, 11:52 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
- 09-19-2010, 12:05 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 09-19-2010, 12:09 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
For the main class, I put:
public static void main(String[] args) throws Exception {
message u = new message();
file c = new file();
- 09-19-2010, 12:12 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 09-19-2010, 12:19 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
For printwriter class
public class file {
public void println()throws Exception {
if (appendToFile) {
io = new PrintWriter(new FileWriter("myfile.txt",true));
}
io = new PrintWriter(new FileWriter("myfile.txt"));
Message class is used to store data. Printwriter class is used to write the data into the file.
- 09-19-2010, 12:32 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 09-19-2010, 12:46 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
I have used those code tags and it doesn't work.
- 09-19-2010, 12:50 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Well, you haven't used them correctly then; note that you can preview your reply without posting it so you can change any mistakes you made. Prepend your code with the tag [code] and append a [/code] tag at the end, that's all there is to it. There's also a little button at the top of your edit window that can do the same ...
kind regards,
Jos
- 09-19-2010, 01:43 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
I really dont' know my mistakes.
In the main file, i put:
public static void main(String[] args) throws Exception {
message u = new message();
file c = new file();
In printwriter class, I put:
public class file {
public void println()throws Exception {
PrintWriter po = null;
if (appendToFile) {
io = new PrintWriter(new FileWriter("myfile.txt",true));
}
io = new PrintWriter(new FileWriter("myfile.txt"));
po.println("");
po.close();
po.append("");
po.flush();
po.close();
- 09-19-2010, 02:04 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
This reply of yours is a mess: where are the code tags? Putting a 'public class file' in a file named PrintWriter is nonsense, it won't compile. Show us your code in code tags and try again; btw, reading compiler error diagnostic messages doesn't hurt. The javac compiler messages are as clear as they come. We can't solve your problem given the random snippets you post here; you can do better than this. btw, where is that 'io' variable defined? Also btw, class and interface names are supposed to start with a capital letter (it's a convention). Also also btw, opening a file in 'append mode' doesn't make sense when you reopen it again overwriting any existing content of the file. Please think before you start randomly banging your keyboard.
kind regards,
JosLast edited by JosAH; 09-19-2010 at 02:09 PM.
Similar Threads
-
Help with PrintWriter code
By eel in forum New To JavaReplies: 4Last Post: 09-19-2010, 07:36 AM -
PrintWriter doesnt work :(
By Addez in forum New To JavaReplies: 11Last Post: 01-17-2010, 05:59 PM -
Help with printwriter.
By Addez in forum New To JavaReplies: 2Last Post: 10-30-2009, 01:58 PM -
Unexpected characters using PrintWriter
By mjwoodford in forum New To JavaReplies: 1Last Post: 09-18-2009, 06:09 PM -
Using Printwriter (java.io.*)
By LifeWithJava in forum New To JavaReplies: 3Last Post: 12-25-2008, 08:07 AM
Bookmarks