Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;

public class Main {
    public static void main(String[] args) throws IOException {

        String str = "from java2s.com!";

        // create string writer
        StringWriter sw = new StringWriter();

        // create buffered writer
        BufferedWriter bw = new BufferedWriter(sw);

        // writing string to writer
        bw.write(str, 1, 4);

        // forces out the characters to string writer
        bw.flush();

        // string buffer is created
        StringBuffer sb = sw.getBuffer();

        System.out.println(sb);

    }
}