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) throws IOException {
    short[] s = { 12345, 12345 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (short j : s) {
        dos.writeShort(j);/*from   ww w. jav  a2s  . c o m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        short k = dis.readShort();
        System.out.print(k);
    }

}

From source file:ImagesWMFPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//  w w  w. j  av a2s.  co m
        PdfWriter.getInstance(document, new FileOutputStream("ImagesWMFPDF.pdf"));
        document.open();

        document.add(new Paragraph("load a WMF image file"));
        Image img = Image.getInstance("logo.WMF");
        document.add(img);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:ImagesPNGPDF.java

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

        document.add(new Paragraph("load a png image file"));
        Image img = Image.getInstance("logo.png");
        document.add(img);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:ImagesJPGPDF.java

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

        document.add(new Paragraph("load a jpg image file"));
        Image jpg = Image.getInstance("logo.jpg");
        document.add(jpg);
    } 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 ww  . j a  v  a  2s  .  c  o  m*/
    ZapfDingbatsList zapfdingbatslist = new ZapfDingbatsList(42, 15);
    zapfdingbatslist.add(new ListItem("A"));
    zapfdingbatslist.add(new ListItem("B"));
    document.add(zapfdingbatslist);
    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  .  jav a2  s  .co m
    document.add(new Phrase("foxdog.jpg"));
    Image img1 = Image.getInstance("foxdog.jpg");
    img1.setAlignment(Image.LEFT);
    document.add(img1);
    document.add(new Phrase("foxdog.gif"));
    Image img2 = Image.getInstance("foxdog.gif");
    img2.setAlignment(Image.MIDDLE);
    document.add(img2);
    document.add(new Phrase("foxdog.png"));
    Image img3 = Image.getInstance("foxdog.png");
    img3.setAlignment(Image.RIGHT);
    document.add(img3);
    document.close();
}

From source file:FileLocking.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("file.txt");
    FileLock fl = fos.getChannel().tryLock();
    if (fl != null) {
        System.out.println("Locked File");
        Thread.sleep(100);//from www  .  jav a  2s  . c  o m
        fl.release();
        System.out.println("Released Lock");
    }
    fos.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    PdfEncryptor.encrypt(new PdfReader("1.pdf"), new FileOutputStream("Encrypted2.pdf"), "Hello".getBytes(),
            "World".getBytes(), PdfWriter.AllowDegradedPrinting, PdfWriter.STRENGTH128BITS);

    // decrypt the file

    PdfReader reader = new PdfReader("Encrypted2.pdf", "World".getBytes());
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("Decrypted1.pdf"));
    stamper.close();//from  w  ww .jav a2 s  . c  o m

    getEncryptionInformation("1.pdf", null);
    getEncryptionInformation("Encrypted2.pdf", "World");
    getEncryptionInformation("Decrypted1.pdf", "World");
}

From source file:PhraseInaChunkPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/* w w w  . j  a  va  2s .c o m*/
        PdfWriter.getInstance(document, new FileOutputStream("PhraseInaChunkPDF.pdf"));

        document.open();

        Phrase phrase = new Phrase(new Chunk("this is a phrase in a chunk\n"));
        document.add(phrase);
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object object = new JButton("push me");

    ObjectOutput out = new ObjectOutputStream(new FileOutputStream("filename.ser"));
    out.writeObject(object);/*from  w  ww  . ja va  2 s  . c om*/
    out.close();

    // Serialize to a byte array
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    out = new ObjectOutputStream(bos);
    out.writeObject(object);
    out.close();

    // Get the bytes of the serialized object
    byte[] buf = bos.toByteArray();
    System.out.println(new String(buf));
}