Results 1 to 3 of 3
  1. #1
    keneid is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default textfield - printstream - text file - to much text

    Hi!

    I using PrintStream and when i stored a text in at text field i got a lot of text.

    Java Code:
            try
    {
        // Open an output stream
        fout = new FileOutputStream ("c:/test.txt");
    
        // Print a line of text
        PrintStream p = new PrintStream(fout);
        p.println (path);     //<<<<------ alot of text from textfield
        p.println (username);
        p.println (password);
        p.println (port);  
        p.println ("test2"); //<<<<--------- work fine in text file
       
        // Close our output stream
        fout.close();
    }
    // Catches any error conditions
    catch (IOException e)
    {
    	System.err.println ("Unable to write to file");
    	System.exit(-1);
    }

    The output in text file look like this
    Java Code:
    java.awt.TextField[textfield0,10,10,380x23,text=Path,editable,selection=0-0]
    java.awt.TextField[textfield1,10,43,380x23,text=Username,editable,selection=0-0]
    java.awt.TextField[textfield2,10,76,380x23,text=Password,editable,selection=0-0]
    java.awt.TextField[textfield3,10,109,380x23,text=Port,editable,selection=0-0]
    test2

    How can the java code only write the text for textfield to file? not everything? You can see println"test2" work.

    thanks!

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    You are probably printing out the textfields themselves instead of the text in the textfields.
    Use the getText() method of JTextField to get the text.

  3. #3
    keneid is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Thank you very much

    p.println (path.getText());

    text file ->
    Path

Similar Threads

  1. Replies: 7
    Last Post: 08-17-2010, 06:00 PM
  2. Replies: 8
    Last Post: 11-06-2009, 07:52 AM
  3. accessing the text of textfield of one class in another
    By vasavi.singh in forum Advanced Java
    Replies: 3
    Last Post: 04-05-2009, 02:54 PM
  4. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 04:04 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:35 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
  •