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 {
    String[] s = { "Hello", "from java2s.com!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (String j : s) {
        dos.writeUTF(j);/*ww  w .j a va 2 s.  c om*/
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

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

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();//from ww w  .  j  a  v a2s . com
    writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(50, 780, 70, 800), "Comment",
            "This is a Comment", false, "Comment"));
    writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(100, 780, 120, 800), "Help",
            "This is a Help ", true, "Help"));
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Hashtable h = new Hashtable();
    h.put("string", "AAA");
    h.put("int", new Integer(26));
    h.put("double", new Double(Math.PI));

    FileOutputStream fileOut = new FileOutputStream("hashtable.ser");
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(h);// ww  w.ja  v  a 2 s  .c o m

    FileInputStream fileIn = new FileInputStream("h.ser");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Hashtable h = (Hashtable) in.readObject();
    System.out.println(h.toString());
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String[] s = { "Hello", "tutorial from java2s.com!!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (String j : s) {
        dos.writeUTF(j);//from  ww w. j  av  a  2s .  c o m
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }

}

From source file:NewPageToStartANewPagePDF.java

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

        document.add(new Paragraph("A"));
        document.newPage();
        document.add(new Paragraph("B"));
        document.newPage();
        document.newPage();
        document.newPage();
        document.add(new Paragraph("C"));
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:Main.java

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

    String[] s = { "Hello", "java2s.com!" };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    for (String j : s) {
        dos.writeUTF(j);//from w ww .j ava  2s . co  m
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }

}

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69, 70 };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    for (byte b : buf) {
        dos.writeChar(b);/*w  w w. j  a  v a2 s  .  co  m*/
    }
    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        char c = dis.readChar();
        System.out.print(c);
    }

}

From source file:RawDataFromImageFilePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from w  w w . jav  a 2 s .com*/
        PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFilePDF.pdf"));
        document.open();

        RandomAccessFile rf = new RandomAccessFile("logo.png", "r");
        int size = (int) rf.length();
        byte imext[] = new byte[size];
        rf.readFully(imext);
        rf.close();

        Image img1 = Image.getInstance(imext);
        img1.setAbsolutePosition(50, 500);
        document.add(img1);

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

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream inStream = new ZipInputStream(new FileInputStream("compressed.zip"));
    OutputStream outStream = new FileOutputStream("extracted.txt");

    byte[] buffer = new byte[1024];
    int read;//w ww  .jav  a 2s.c o  m
    ZipEntry entry;
    if ((entry = inStream.getNextEntry()) != null) {
        while ((read = inStream.read(buffer)) > 0) {
            outStream.write(buffer, 0, read);
        }
    }
    outStream.close();
    inStream.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  2s  .c  o  m
    Chunk c;
    c = new Chunk("Quick brown fox jumps over the lazy dog.");
    c.setUnderline(new Color(0xFF, 0x00, 0x00), 0.0f, 0.3f, 0.0f, 0.4f, PdfContentByte.LINE_CAP_ROUND);

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