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 {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("3.pdf"));
    writer.setStrictImageSequence(true);
    document.open();//  w  w w .  j  a v  a  2s .co m
    Image jpg = Image.getInstance("dog1.jpg");
    Image gif = Image.getInstance("dog2.gif");
    document.add(jpg);
    document.add(gif);
    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  ava2  s .c  o  m*/
    Image img = Image.getInstance("dog.jpg");
    img.setAbsolutePosition(50, 600);
    document.add(img);
    img.setAbsolutePosition(50, 300);
    document.add(img);
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String s = "Hello World from java2s.com";

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

    // write something in the file
    oout.writeUnshared(s);// w ww.j  a v a 2s.  com
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print the unshared object
    System.out.println(ois.readUnshared());
    ois.close();
}

From source file:CreateParagraph.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
    document.open();/*from  w w w.j  a  v  a  2s  .  c  om*/
    document.add(new Paragraph("Hello World"));
    document.close();
}

From source file:Main.java

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

    String s = "Hello World from java2s.com!";

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

    oout.writeUTF(s);//from   w ww . ja  va  2  s.  com
    oout.writeUTF("This is an example from java2s.com");
    oout.flush();
    oout.close();
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    System.out.println(ois.readUTF());

    System.out.println(ois.readUTF());
    ois.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JarFile f = new JarFile("a.jar");
    Pack200.Packer packer = Pack200.newPacker();
    OutputStream out = new FileOutputStream("a.pack");
    packer.pack(f, out);/*from www.  j  av  a  2  s  .c  om*/
    out.close();
}

From source file:Main.java

public static void main(String[] args) {
    File outputFile = new File("test.txt");

    try (FileChannel fileChannel = new FileOutputStream(outputFile).getChannel()) {
        String text = getText();//from w w w  . ja v  a2s. c  om
        byte[] byteData = text.toString().getBytes("UTF-8");
        ByteBuffer buffer = ByteBuffer.wrap(byteData);
        fileChannel.write(buffer);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

From source file:Main.java

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

    String s = "Hello World from java2s.com";

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

    // write something in the file
    oout.writeUTF(s);/*  w  w w.j  a v a 2  s .com*/
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print the whole content
    byte[] b = new byte[13];
    ois.readFully(b);
    String array = new String(b);
    System.out.println(array);
    ois.close();
}

From source file:EndOfLinePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  w  w  w.  j  a va 2  s  .  c o  m
        PdfWriter.getInstance(document, new FileOutputStream("EndOfLinePDF.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");
        document.add(chunk);

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ZipInputStream in = new ZipInputStream(new FileInputStream("source.zip"));
    OutputStream out = new FileOutputStream("target");
    byte[] buf = new byte[1024];
    int len;//  ww  w .  ja  v  a 2  s.c o m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.close();
    in.close();
}