Example usage for java.io FileOutputStream FileOutputStream

List of usage examples for java.io FileOutputStream FileOutputStream

Introduction

In this page you can find the example usage for java.io FileOutputStream FileOutputStream.

Prototype

public FileOutputStream(FileDescriptor fdObj) 

Source Link

Document

Creates a file output stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    FileChannel fc = new FileOutputStream("data2.txt").getChannel();
    fc.write(ByteBuffer.wrap("Some text".getBytes()));
    fc.close();/*ww w  .  ja v a  2 s  .  c  o m*/
    fc = new FileInputStream("data2.txt").getChannel();
    ByteBuffer buff = ByteBuffer.allocate(BSIZE);
    fc.read(buff);
    buff.flip();

    System.out.println(buff.asCharBuffer());
    // Decode using this system's default Charset:
    buff.rewind();
    String encoding = System.getProperty("file.encoding");
    System.out.println("Decoded using " + encoding + ": " + Charset.forName(encoding).decode(buff));
    // Or, we could encode with something that will print:
    fc = new FileOutputStream("data2.txt").getChannel();
    fc.write(ByteBuffer.wrap("Some text".getBytes("UTF-16BE")));
    fc.close();

}

From source file:MainClass.java

License:asdf

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer3 = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));

    writer3.setPdfVersion(PdfWriter.VERSION_1_5);
    writer3.setViewerPreferences(PdfWriter.DisplayDocTitle | PdfWriter.PageLayoutTwoPageLeft);

    document.addTitle("Hello World");
    document.open();/*  ww w.java 2s . c o  m*/
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {/*from  w  ww . ja v  a2s . c om*/

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder());

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {//from  w  w w.  java2s. co  m

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset());

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();/*w w  w. ja  va2  s. c om*/
    writer.setPageEmpty(true);
    document.newPage();
    writer.setPageEmpty(false);
    document.newPage();
    document.add(new Paragraph("Hello World"));
    document.newPage();
    writer.setPageEmpty(true);
    document.newPage();
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.addTitle("title");
    document.addSubject("subject");
    document.addKeywords("keywords");
    document.addCreator("creator");
    document.addAuthor("author");
    writer.createXmpMetadata();//  w w  w  . j av a2  s .  co m
    document.open();
    document.add(new Paragraph("Hello World"));
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//from  w  w  w .  ja  v a 2 s . co  m
    PdfPTable table = new PdfPTable(10);
    for (int k = 1; k <= 100; ++k) {
        table.addCell("number " + k);
    }
    table.setTotalWidth(800);
    table.writeSelectedRows(0, 5, 0, -1, 50, 650, writer.getDirectContent());
    document.newPage();
    table.writeSelectedRows(5, -1, 0, -1, 50, 650, writer.getDirectContent());
    document.close();
}

From source file:ExplicitChannelWrite.java

public static void main(String args[]) {
    FileOutputStream fOut;/*from w w  w .  j  a  v a 2  s. co m*/
    FileChannel fChan;
    ByteBuffer mBuf;

    try {
        fOut = new FileOutputStream("test.txt");
        fChan = fOut.getChannel();
        mBuf = ByteBuffer.allocateDirect(26);
        for (int i = 0; i < 26; i++)
            mBuf.put((byte) ('A' + i));
        mBuf.rewind();
        fChan.write(mBuf);
        fChan.close();
        fOut.close();
    } catch (IOException exc) {
        System.out.println(exc);
        System.exit(1);
    }
}

From source file:BufferDiff.java

public static void main(String args[]) throws IOException {
    FileOutputStream unbufStream;
    BufferedOutputStream bufStream;
    unbufStream = new FileOutputStream("test.one");
    bufStream = new BufferedOutputStream(new FileOutputStream("test.two"));
    System.out.println("Write file unbuffered: " + time(unbufStream) + "ms");
    System.out.println("Write file  buffered: " + time(bufStream) + "ms");
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//from   ww  w.j a v  a  2  s  .  com
    Image tiff = Image.getInstance("dog.tiff");
    document.add(tiff);
    document.add(new Paragraph("DPI X: " + tiff.getDpiX() + "; DPI Y: " + tiff.getDpiY()));

    document.close();
}