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 {
    User a = new User("A", "B");
    System.out.println("logon a = " + a);
    ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("User.out"));
    o.writeObject(a);/*from  w  w w.  j ava2s. co  m*/
    o.close();

    Thread.sleep(1000); // Delay for 1 second

    ObjectInputStream in = new ObjectInputStream(new FileInputStream("User.out"));
    System.out.println("Recovering object at " + new Date());
    a = (User) in.readObject();
    System.out.println("logon a = " + a);
}

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"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    document.open();//from   w  w  w.  j  a  v a  2  s.  c o  m
    PdfLayer layer = new PdfLayer("Do you see me?", writer);

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    cb.setTextMatrix(50, 790);
    cb.setLeading(24);
    cb.setFontAndSize(bf, 18);
    cb.showText("Do you see me?");
    cb.beginLayer(layer);
    cb.newlineShowText("this is a test");
    cb.endLayer();
    cb.endText();
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    String outputFile = "new.zip";
    // Default to maximum compression
    int level = 9;
    int start = 1;

    FileOutputStream fout = new FileOutputStream(outputFile);
    ZipOutputStream zout = new ZipOutputStream(fout);
    zout.setLevel(level);//w  ww.  j av a  2s .  co  m
    for (int i = start; i < args.length; i++) {
        ZipEntry ze = new ZipEntry(args[i]);
        FileInputStream fin = new FileInputStream(args[i]);
        try {
            System.out.println("Compressing " + args[i]);
            zout.putNextEntry(ze);
            for (int c = fin.read(); c != -1; c = fin.read()) {
                zout.write(c);
            }
        } finally {
            fin.close();
        }
    }
    zout.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CheckedOutputStream checksum = new CheckedOutputStream(new FileOutputStream("data.zip"), new Adler32());
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum));

    int size = 0;
    byte[] buffer = new byte[1024];

    File dir = new File(".");
    String[] files = dir.list();//from  w  w w.  ja  v  a  2  s  . c om

    for (int i = 0; i < files.length; i++) {
        System.out.println("Compressing: " + files[i]);
        FileInputStream fis = new FileInputStream(files[i]);
        ZipEntry zipEntry = new ZipEntry(files[i]);
        zos.putNextEntry(zipEntry);

        while ((size = fis.read(buffer, 0, buffer.length)) > 0) {
            zos.write(buffer, 0, size);
        }
        zos.closeEntry();
        fis.close();
    }
    zos.close();
    System.out.println("Checksum   : " + checksum.getChecksum().getValue());
}

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();/*w  w  w  . jav  a 2s.co  m*/

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    PdfPCell cell = new PdfPCell(
            new Paragraph("Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog."));
    table.addCell("different padding for left, right, top and bottom");
    cell.setPaddingLeft(20);
    cell.setPaddingRight(50);
    cell.setPaddingTop(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    document.add(table);
    document.close();
}

From source file:TableCellSpanPDF.java

public static void main(String[] args) {
    Document document = new Document();

    try {/*from  w w  w .  j a  va2s .c  o m*/
        PdfWriter.getInstance(document, new FileOutputStream("TableCellSpanPDF.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(3);
        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");

        cell = new PdfPCell(new Paragraph("cell test1"));
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph("cell test2"));
        cell.setColspan(2);
        table.addCell(cell);

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

From source file:ImageScalingAbsolutePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  w  w w  . java  2 s  .  c  om
        PdfWriter.getInstance(document, new FileOutputStream("ImageScalingAbsolutePDF.pdf"));
        document.open();
        Image png = Image.getInstance("logo.png");
        png.scaleAbsolute(160, 120);

        document.add(png);

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

From source file:LayerShapeOnTextPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  w  w w .  j  ava2 s  .  com
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("LayerShapeOnTextPDF.pdf"));
        document.open();

        Paragraph p = new Paragraph();
        for (int i = 0; i < 100; i++)
            p.add(new Chunk("Text Text Text Text Text Text Text Text "));
        document.add(p);

        PdfContentByte cb = writer.getDirectContent();
        cb.setRGBColorFill(0xFF, 0xFF, 0xFF);
        cb.circle(250.0f, 500.0f, 50.0f);
        cb.fill();

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

From source file:LockingCellWidthsPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    try {// w ww . j a va 2 s. c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("LockingCellWidthsPDF.pdf"));
        document.open();

        float[] widths = { 0.1f, 0.1f, 0.05f, 0.75f };
        PdfPTable table = new PdfPTable(widths);
        table.addCell("10%");
        table.addCell("10%");
        table.addCell("5%");
        table.addCell("75%");
        table.addCell("111111111111111111111111111");
        table.addCell("111111111111111");
        table.addCell("11111");
        table.addCell("11");

        table.setTotalWidth(300);
        table.setLockedWidth(true);

        document.add(table);

    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("HelloWorldRead.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("HelloWorldStamper2.pdf"));
    Image img = Image.getInstance("watermark.jpg");
    img.setAbsolutePosition(200, 400);/*from  www  .ja  v  a 2  s  . co  m*/
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    PdfContentByte under, over;
    int total = reader.getNumberOfPages() + 1;
    for (int i = 1; i < total; i++) {
        stamper.setRotateContents(false);
        under = stamper.getUnderContent(i);
        under.addImage(img);

    }
    stamper.close();
}