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:ChunksTextRiseUnderLinePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from   w ww .  j  a v  a  2  s  .c  om
        PdfWriter.getInstance(document, new FileOutputStream("ChunksTextRiseUnderLinePDF.pdf"));
        document.open();

        Chunk test = new Chunk("some text");
        float subscript = -8.0f;
        test.setTextRise(subscript);
        test.setUnderline(new Color(0xFF, 0x00, 0x00), 3.0f, 0.0f, -5.0f + subscript, 0.0f,
                PdfContentByte.LINE_CAP_ROUND);

        document.add(test);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:CopyChannels.java

public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    FileChannel in = new FileInputStream(fromFileName).getChannel();
    FileChannel out = new FileOutputStream(toFileName).getChannel();

    ByteBuffer buff = ByteBuffer.allocate(32 * 1024);

    while (in.read(buff) > 0) {
        buff.flip();/*  w  w w . j  a v a  2s  .c o  m*/
        out.write(buff);
        buff.clear();
    }

    in.close();
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;//from  w w w  . ja v a2  s.  c  o m
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("1.pdf"));
    writer.setPdfVersion('1');
    document.open();
    document.add(new Paragraph("Hello World"));
    document.close();
}

From source file:DocumentPageCountPDF.java

public static void main(String args[]) {
    try {//  w w  w .j a  va 2 s .co m
        Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("DocumentPageCountPDF.pdf"));
        doc.open();

        Paragraph p = new Paragraph("text");

        doc.add(p);

        doc.close();
        System.out.println(writer.getPageNumber());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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.jav a 2s .c  o  m*/

    PdfPTable table = new PdfPTable(3);
    table.setTotalWidth(216f);
    table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    cell.setColspan(3);
    table.addCell(cell);
    table.addCell("1.1");
    table.addCell("2.1");
    table.addCell("3.1");
    table.addCell("1.2");
    table.addCell("2.2");
    table.addCell("3.2");
    document.add(table);
    document.close();
}

From source file:EndOfLineWithTextRenderModePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from w  ww .j  av  a2  s .c  o m*/
        PdfWriter.getInstance(document, new FileOutputStream("EndOfLineWithTextRenderModePDF.pdf"));

        document.open();

        Chunk chunk = new Chunk(
                "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0");
        chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_STROKE, 0.3f, new Color(30, 30, 30));
        document.add(chunk);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

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 w w  w .  j  a  va2s.  c  om
    float[] widths1 = { 1f, 1f, 2f };
    PdfPTable table = new PdfPTable(widths1);
    PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    cell.setColspan(3);
    table.addCell(cell);
    table.addCell("1.1");
    table.addCell("2.1");
    table.addCell("3.1");
    table.addCell("1.2");
    table.addCell("2.2");
    table.addCell("3.2");
    document.add(table);
    float[] widths2 = { 2f, 1f, 1f };
    table.setWidths(widths2);
    document.add(table);
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    File fromFile = new File("fromFile.txt");
    File toFile = new File("toFile.txt");
    FileInputStream inFile = new FileInputStream(fromFile);
    FileOutputStream outFile = new FileOutputStream(toFile);
    FileChannel inChannel = inFile.getChannel();
    FileChannel outChannel = outFile.getChannel();
    int bytesWritten = 0;
    long byteCount = inChannel.size();
    while (bytesWritten < byteCount) {
        bytesWritten += inChannel.transferTo(bytesWritten, byteCount - bytesWritten, outChannel);
    }/*from w w w.j  av a 2 s  .  com*/
    inFile.close();
    outFile.close();
}

From source file:Main.java

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

    float[] fbuf = { 123.345f, 234.567f, 123.123f, 123.123f, 123.123f, 123.345f };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (float f : fbuf) {
        dos.writeFloat(f);//w  w w.  j  a  v  a 2s  .co m
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        float c = dis.readFloat();
        System.out.print(c + " ");
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;//from  ww  w . j a  v a  2 s  .  c o m
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    cb.setLineWidth(3);
    cb.moveTo(40, 480);
    cb.lineTo(320, 480);
    cb.stroke();
    cb.setLineDash(6, 0);
    cb.moveTo(40, 450);
    cb.lineTo(320, 450);
    cb.stroke();
    float[] dash1 = { 10, 5, 5, 5, 20 };
    cb.setLineDash(dash1, 5);
    cb.moveTo(40, 440);
    cb.lineTo(320, 440);
    cb.stroke();
    float[] dash2 = { 9, 6, 0, 6 };
    cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
    cb.setLineDash(dash2, 0);
    cb.moveTo(40, 430);
    cb.lineTo(320, 430);
    cb.stroke();

    cb.restoreState();
    document.close();
}