Results 1 to 3 of 3
  1. #1
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default Start write at the eol.

    Hello!

    Newbi have a small problem, I Have searched sun´s doc but can´t find what i need.
    This is the code.

    Java Code:
           
            // Read the file
    	try {
    	BufferedReader in = new BufferedReader(new InputStreamReader 
            (new FileInputStream("c:/java/readme.txt")));       
    	String str;
    	while ((str = in.readLine()) != null) {
    	System.out.println(str);
    	}
    	in.close();
    	}catch (IOException e) {
    	e.printStackTrace();
    }      // End of Read the file
        
    
    	//Write the input to file!
    	try {
    	Writer out = new OutputStreamWriter(new FileOutputStream("c:/java/readme.txt"));
    	out.write(aTextField.getText());
    	out.close();                
    	} catch (IOException e) {	  			
    	e.printStackTrace(); 
    }	// End of write
    }}}
    What this does is read the file, and write the new input to readme.txt. BUT i want it to start write at the end of line. And not write over the old text as it does now. thank´s for any help.

    /ocean

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Have a look at the FileWriter class:
    FileWriter (Java 2 Platform SE v1.4.2)
    I die a little on the inside...
    Every time I get shot.

  3. #3
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    A very big thank´s Supamagier. Found .

    "public FileWriter(String fileName,
    boolean append)
    throws IOException

    Parameters:
    fileName - String The system-dependent filename.
    append - boolean if true, then data will be written to the end of the file rather than the beginning.


    And that made me do this.

    Java Code:
    private boolean append ;<------
    try {
    	Writer out = new OutputStreamWriter(new FileOutputStream("c:/java/readme.txt",append = true));<------
    	out.write(aTextField.getText());
    	out.close();                
    	} catch (IOException e) {	  			
    	e.printStackTrace(); 
    	// End of write
    EDIT : btw how do i mark this "solved"?
    Last edited by ocean; 09-26-2009 at 01:20 PM.

Similar Threads

  1. Replies: 5
    Last Post: 03-20-2009, 11:04 PM
  2. Where to start?
    By McChill in forum New To Java
    Replies: 5
    Last Post: 02-19-2009, 03:26 PM
  3. Web Start
    By DannyZB in forum NetBeans
    Replies: 0
    Last Post: 11-14-2008, 01:58 PM
  4. How to start
    By sand.softnet1 in forum New To Java
    Replies: 5
    Last Post: 09-05-2008, 08:41 PM
  5. How to start
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 09:43 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
  •