- Java.io package classes
- Java.io - Home
- Java.io - BufferedInputStream
- Java.io - BufferedOutputStream
- Java.io - BufferedReader
- Java.io - BufferedWriter
- Java.io - ByteArrayInputStream
- Java.io - ByteArrayOutputStream
- Java.io - CharArrayReader
- Java.io - CharArrayWriter
- Java.io - Console
- Java.io - DataInputStream
- Java.io - DataOutputStream
- Java.io - File
- Java.io - FileDescriptor
- Java.io - FileInputStream
- Java.io - FileOutputStream
- Java.io - FilePermission
- Java.io - FileReader
- Java.io - FileWriter
- Java.io - FilterInputStream
- Java.io - FilterOutputStream
- Java.io - FilterReader
- Java.io - FilterWriter
- Java.io - InputStream
- Java.io - InputStreamReader
- Java.io - LineNumberInputStream
- Java.io - LineNumberReader
- Java.io - ObjectInputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectOutputStream
- io - ObjectOutputStream.PutField
- Java.io - ObjectStreamClass
- Java.io - ObjectStreamField
- Java.io - OutputStream
- Java.io - OutputStreamWriter
- Java.io - PipedInputStream
- Java.io - PipedOutputStream
- Java.io - PipedReader
- Java.io - PipedWriter
- Java.io - PrintStream
- Java.io - PrintWriter
- Java.io - PushbackInputStream
- Java.io - PushbackReader
- Java.io - RandomAccessFile
- Java.io - Reader
- Java.io - SequenceInputStream
- Java.io - SerializablePermission
- Java.io - StreamTokenizer
- Java.io - StringBufferInputStream
- Java.io - StringReader
- Java.io - StringWriter
- Java.io - Writer
- Java.io package extras
- Java.io - Interfaces
- Java.io - Exceptions
- Java.io package Useful Resources
- Java.io - Discussion
Java.io.BufferedWriter.append() Method
Description
The java.io.BufferedWriter.append(CharSequence csq, int start, int end) method appends subsequence defined by the start and the end postions of the specified character sequence to this write.
Declaration
Following is the declaration for java.io.BufferedWriter.append(CharSequence csq, int start, int end) method
public Writer append(CharSequence csq, int start, int end)
Parameters
csq − It is the character sequence to append.
start − The index of the first character of the subsequence.
end − The index of the next character following the end character of the subsequence.
Return Value
This writer
Exception
IndexOutOfBoundException − If end is greater than csq.length(), start or end are negative, or start is greater than end.
IOException − If an I/O error occurs..
Example
The following example shows the usage of java.io.BufferedWriter.append(CharSequence csq, int start, int end) method.
package com.tutorialspoint; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringWriter; public class BufferedWriterDemo { public static void main(String[] args) throws IOException { StringWriter sw = null; BufferedWriter bw = null; CharSequence csq = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; try{ // create string writer sw = new StringWriter(); //create buffered writer bw = new BufferedWriter(sw); // append subsequence of character sequence. bw.append(csq, 5, 11); bw.append(" "); bw.append(csq, 3, 7); bw.append(" "); bw.append(csq, 2, 8); // forces out the characters to string writer bw.flush(); // string buffer is created StringBuffer sb = sw.getBuffer(); //prints the string System.out.println(sb); }catch(IOException e){ // if I/O error occurs e.printStackTrace(); }finally{ // releases any system resources associated with the stream if(sw!=null) sw.close(); if(bw!=null) bw.close(); } } }
Let us compile and run the above program, this will produce the following result:
FGHIJK DEFG CDEFGH