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

public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
        try {//  www . j a v a2 s  .  c o m
            FileInputStream fin = new FileInputStream(args[i]);
            FileOutputStream fout = new FileOutputStream(args[i] + "dfl");
            DeflaterOutputStream dos = new DeflaterOutputStream(fout);
            for (int c = fin.read(); c != -1; c = fin.read()) {
                dos.write(c);
            }
            dos.close();
            fin.close();
        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;//  w  w w. java  2s.  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(8);
    cb.setLineCap(PdfContentByte.LINE_JOIN_MITER);
    cb.moveTo(72, 640);
    cb.lineTo(144, 640);
    cb.stroke();
    cb.restoreState();
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;/*from  w w w. ja  v a  2 s.c  om*/
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    cb.setLineWidth(8);
    cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
    cb.moveTo(72, 640);
    cb.lineTo(144, 640);
    cb.stroke();
    cb.restoreState();
    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();/* w  w  w. java 2  s  .  com*/
    Font font = new Font();
    font.setStyle(Font.UNDERLINE);
    Chunk chunk = new Chunk("java2s", font);
    chunk.setAction(new PdfAction("http://www.java2s.com"));
    document.add(chunk);

    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;/*from   w w  w . j av  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();
    cb.setLineWidth(8);
    cb.setLineCap(PdfContentByte.LINE_CAP_BUTT);
    cb.moveTo(72, 640);
    cb.lineTo(144, 640);
    cb.stroke();
    cb.restoreState();
    document.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {/*www.  jav  a 2 s  .c  o m*/

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, java.nio.charset.StandardCharsets.UTF_8);

        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.getInstance(document, new FileOutputStream("2.pdf"));

    document.open();//  w  w w  . j  a  v  a 2 s  .  c om
    BaseFont bf = BaseFont.createFont("esl_gothic_shavian.otf", "Cp1252", BaseFont.EMBEDDED);
    System.err.println(bf.getClass().getName());
    Font font = new Font(bf, 12);
    document.add(new Paragraph("abced"));
    document.add(new Paragraph("this is a test", font));
    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("clipping_path.pdf"));
    document.open();/*from   w  ww  .  j a v a2s . c o  m*/
    Image img = Image.getInstance("dog.jpg");
    float w = img.scaledWidth();
    float h = img.scaledHeight();
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    cb.circle(260, 700, 70);
    cb.clip();
    cb.newPath();
    cb.addImage(img, w, 0, 0, h, 36, 620);
    cb.restoreState();

    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  2s  .  c om*/
    Font font = new Font();
    font.setStyle(Font.UNDERLINE);
    font.setColor(new GrayColor(0.3f));
    Anchor anchor = new Anchor("java2s", font);
    anchor.setReference("http://www.java2s.com");
    document.add(anchor);
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;/*from   ww  w .  j av  a  2s  .c  om*/
    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();
    }
    cb.restoreState();
    document.close();
}