BufferedWriter newLine Example

BufferedWriter class newLine example. This example shows you how to use newLine method.


BufferedWriter class newLine example.public void newLine() throws IOException Writes a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.

here is the code

/**
 * @ # NewLine.java
 * A class repersenting use to newLine method 
 * of BufferedWriter class in java.io package
 * version 29 May 2008
 * author Rose India 
 */
import java.io.*;

public class NewLine {

    public static void main(String[] argsthrows Exception {
        // Create a new instance of a BufferedWriter object using
        // a StringWriter.
        StringWriter stringWriter = new StringWriter();
        BufferedWriter bufWriter = new BufferedWriter(stringWriter);

        // Write to the underlying StringWriter.
        String s = "This is the string being written.";

        // Print out the first 12 characters.
        bufWriter.write(s, 012);

        // Print a newline character.
        bufWriter.newLine();

        // Print the rest of the string.
        bufWriter.write(s, 12, s.length() 12);
        bufWriter.flush();
        System.out.println(stringWriter.getBuffer());

        // Close the BufferedWriter object and the underlying
        // StringWriter object.
        stringWriter.close();
        bufWriter.close();
    }
}

Output
This is the
string being written.

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US