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 {

    long[] l = { 1234567890L, 987654321L };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (long j : l) {
        dos.writeLong(j);/*  www . j  av  a  2s .  co  m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");

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

From source file:Main.java

public static void main(String[] args) throws IOException {
    int[] i = { 123, 234, 345, 456, 678 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);//from www.j  a v a 2 s  . c o  m
    }
    dos.flush();

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

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

From source file:Main.java

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

    FileInputStream fin = null;//from   w w w. j  ava  2s  . c o  m
    FileOutputStream fout = null;

    File file = new File("C:/myfile1.txt");

    fin = new FileInputStream(file);
    fout = new FileOutputStream("C:/myfile2.txt");

    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = fin.read(buffer)) > 0) {
        fout.write(buffer, 0, bytesRead);
    }
    fin.close();
    fout.close();
}

From source file:Main.java

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

    int[] i = { 123, 234, 454, 567, 789 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);/*w w w  .ja  va 2s.co m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");

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

From source file:StrokeColorPDF.java

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

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.setLineWidth(10f);
        cb.setRGBColorStrokeF(0f, 255f, 0f);
        cb.moveTo(100, 700);
        cb.lineTo(200, 800);

        cb.stroke();

    } 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(new Rectangle(792, 612));
    PdfWriter.getInstance(document, new FileOutputStream("1.pdf"));
    document.open();/* ww w  . j a  v a  2  s . c o m*/
    document.add(new Paragraph("Hello World"));
    document.close();
}

From source file:MainClass.java

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

From source file:MainClass.java

public static void main(String args[]) {
    FileOutputStream fileOutputStream;
    FileChannel fileChannel;//from   www . ja v a2s . c o  m
    ByteBuffer byteBuffer;

    try {
        fileOutputStream = new FileOutputStream("test.txt");
        fileChannel = fileOutputStream.getChannel();
        byteBuffer = ByteBuffer.allocateDirect(26);

        for (int i = 0; i < 26; i++)
            byteBuffer.put((byte) ('A' + i));
        byteBuffer.rewind();
        fileChannel.write(byteBuffer);
        fileChannel.close();
        fileOutputStream.close();
    } catch (IOException exc) {
        System.out.println(exc);
    }
}

From source file:Main.java

public static void main(String[] atgs) throws Exception {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java.txt")));
    out.writeUTF("");
    out.writeBytes("a");
    out.writeChars("aaa");
    out.close();/*from   w ww.j a  va2 s.  c om*/
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("java.txt")));
    System.out.println(in.readUTF());
    byte[] buf = new byte[1024];
    int len = in.read(buf);
    System.out.println(new String(buf, 0, len));
    in.close();
}

From source file:ShapeDashLinePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from w w  w  .  j av a2  s.c om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ShapeDashLinePDF.pdf"));

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.setLineWidth(10f);
        cb.setLineDash(3, 3, 0);
        cb.moveTo(100, 700);
        cb.lineTo(200, 800);

        cb.stroke();

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