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[] a) throws Exception {

    List list = Arrays.asList(new String[] { "A", "B", "C", "D" });

    FileOutputStream fos = new FileOutputStream("list.ser");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(list);/*from   w  ww. j  av a  2  s . c  o m*/
    oos.close();

    FileInputStream fis = new FileInputStream("list.ser");
    ObjectInputStream ois = new ObjectInputStream(fis);
    List anotherList = (List) ois.readObject();
    ois.close();

    System.out.println(anotherList);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;/* w  w w .  j a v  a  2s .c o  m*/
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.moveTo(100, 100);
    cb.lineTo(200, 200);
    cb.moveTo(300, 20);
    cb.lineTo(1, 3);
    cb.moveTo(0, 0);
    cb.curveTo(10, 10, 200, 200, 300, 30);

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

From source file:Main.java

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

    String s = "Hello World from java2s.com";
    byte[] b = { 'e', 'x', 'a', 'm', 'p', 'l', 'e' };

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeObject(s);/*from ww  w  . ja  va  2  s .  c om*/
    oout.writeObject(b);
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print an object and cast it as string
    System.out.println((String) ois.readObject());

    // read and print an object and cast it as string
    byte[] read = (byte[]) ois.readObject();
    String s2 = new String(read);
    System.out.println(s2);
    ois.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;/*from  w w  w .  j  a  v  a  2 s  .  co  m*/
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    for (int i = 25; i > 0; i--) {
        cb.setLineWidth((float) i / 10);
        cb.moveTo(40, 806 - (5 * i));
        cb.lineTo(320, 806 - (5 * i));
        cb.stroke();
    }

    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();/* w  w  w  .j  a  v  a  2  s. co  m*/
    PdfContentByte cb = writer.getDirectContent();
    String text = "this is a test";
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    cb.setFontAndSize(bf, 12);
    cb.beginText();

    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250, 650, 0);
    cb.endText();
    document.close();
}

From source file:Convert2pdfptable.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from w  w w  .ja  va2  s .  com*/
        PdfWriter.getInstance(document, new FileOutputStream("Convert2pdfptable.pdf"));

        document.open();

        Table table = new Table(2);
        table.setBorderWidth(1);
        table.setPadding(10);
        Cell cell = new Cell("header");
        cell.setHeader(true);
        cell.setColspan(2);
        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");
        table.setConvert2pdfptable(true);
        document.add(table);

    } 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  ww  w. j av a  2  s.co  m

    Paragraph p = new Paragraph(new Chunk("Click to open test.txt in Notepad.")
            .setAction(new PdfAction("c:/windows/notepad.exe", "test.txt", "open", "c:\\")));
    document.add(p);
    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 .ja  v a 2  s .  co m
    float textrise = 6.0f;
    Chunk c;
    for (String s : "this is a test".split(" ")) {
        c = new Chunk(s);
        c.setTextRise(textrise);
        c.setUnderline(new Color(0xC0, 0xC0, 0xC0), 0.2f, 0.0f, 0.0f, 0.0f, PdfContentByte.LINE_CAP_BUTT);
        document.add(c);
        textrise -= 2.0f;
    }
    document.close();
}

From source file:Main.java

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

    FileOutputStream fout = new FileOutputStream(outputFile);
    ZipOutputStream zout = new ZipOutputStream(fout);
    zout.setLevel(level);/*from  w  ww  . j a  v a  2  s .c  o  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:FontStyle3PDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*w  w w  .j a v  a  2s. com*/
        PdfWriter.getInstance(document, new FileOutputStream("FontStyle3PDF.pdf"));
        document.open();
        Phrase myPhrase = new Phrase("FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.BOLD)",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.BOLD));
        document.add(myPhrase);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}