Results 1 to 10 of 10
  1. #1
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Exclamation Help with printwriter class

    What should I put in the main document if I write printwriter in separate class?
    I just put printwriter p = new printwriter(); in the main document.
    And I didn't get the text file after I run the command window. May I know what's wrong?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    What should I put in the main document if I write printwriter in separate class?
    I just put printwriter p = new printwriter(); in the main document.
    And I didn't get the text file after I run the command window. May I know what's wrong?
    Code? And don't forget thos tags ...

    kind regards,

    Jos

  3. #3
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    For the main class, I put:

    public static void main(String[] args) throws Exception {
    message u = new message();
    file c = new file();

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    For the main class, I put:

    public static void main(String[] args) throws Exception {
    message u = new message();
    file c = new file();
    Great, now where is that printwriter class you were talking about? I am not psychic in the weekends ... and what is that message class all about? And where are the [code] tags I asked you about several times?

    kind regards,

    Jos

  5. #5
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    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.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    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.
    First use those [code] tags and then we'll talk again.

    Jos

  7. #7
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    I have used those code tags and it doesn't work.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    I have used those code tags and it doesn't work.
    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

  9. #9
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    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();

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    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();
    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,

    Jos
    Last edited by JosAH; 09-19-2010 at 02:09 PM.

Similar Threads

  1. Help with PrintWriter code
    By eel in forum New To Java
    Replies: 4
    Last Post: 09-19-2010, 07:36 AM
  2. PrintWriter doesnt work :(
    By Addez in forum New To Java
    Replies: 11
    Last Post: 01-17-2010, 05:59 PM
  3. Help with printwriter.
    By Addez in forum New To Java
    Replies: 2
    Last Post: 10-30-2009, 01:58 PM
  4. Unexpected characters using PrintWriter
    By mjwoodford in forum New To Java
    Replies: 1
    Last Post: 09-18-2009, 06:09 PM
  5. Using Printwriter (java.io.*)
    By LifeWithJava in forum New To Java
    Replies: 3
    Last Post: 12-25-2008, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •