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) {
    Card card = new Card();
    try {//from w  w  w. ja  va 2  s . co  m
        FileOutputStream out = new FileOutputStream("card.out");
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(card);
        oos.flush();
        oos.close();
    } catch (Exception e) {
        System.out.println("Problem serializing: " + e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    OutputStream fileOutputStream;
    try {/*from w  ww . jav a 2  s. co m*/
        fileOutputStream = new FileOutputStream("c:/a.txy");
        Runtime runTime = Runtime.getRuntime();
        runTime.getLocalizedOutputStream(fileOutputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File outFile = new File("stdout.txt");
    PrintStream ps = new PrintStream(new FileOutputStream(outFile));

    System.out.println(outFile.getAbsolutePath());

    System.setOut(ps);/*from w ww. java 2  s.  c om*/

    System.out.println("Hello world!");
    System.out.println("Java I/O  is cool!");
}

From source file:FileIOApp.java

public static void main(String args[]) throws IOException {
    FileOutputStream outStream = new FileOutputStream("test.txt");
    String s = "This is a test.";
    for (int i = 0; i < s.length(); ++i)
        outStream.write(s.charAt(i));//from  w w w  . j a  v  a2s .c om
    outStream.close();
    FileInputStream inStream = new FileInputStream("test.txt");
    int inBytes = inStream.available();
    System.out.println("inStream has " + inBytes + " available bytes");
    byte inBuf[] = new byte[inBytes];
    int bytesRead = inStream.read(inBuf, 0, inBytes);
    System.out.println(bytesRead + " bytes were read");
    System.out.println("They are: " + new String(inBuf));
    inStream.close();
    File f = new File("test.txt");
    f.delete();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    FileChannel fc = new FileOutputStream("data2.txt").getChannel();
    ByteBuffer buff = ByteBuffer.allocate(24); // More than needed
    buff.asCharBuffer().put("Some text");
    fc.write(buff);/* w ww .j av a 2 s.  co m*/
    fc.close();

    fc = new FileInputStream("data2.txt").getChannel();
    buff.clear();
    fc.read(buff);
    buff.flip();
    System.out.println(buff.asCharBuffer());

}

From source file:MainClass.java

public static void main(String[] a) {
    FileOutputStream outputFile = null; // Place to store the stream reference
    try {/*www  .j  a v  a 2s. c  o m*/
        outputFile = new FileOutputStream("myFile.txt");
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {/*from   w  w  w .j av a  2  s  .co m*/

        OutputStream os = new FileOutputStream("test.txt");

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

        os.write(70);
        os.write(71);

        for (int i = 0; i < 2; i++) {
            System.out.print((char) is.read());
        }
        os.close();
        is.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] arguments) {
    try {//from   w ww.  j a va  2  s .  c o  m
        FileOutputStream file = new FileOutputStream("p.dat");
        BufferedOutputStream buff = new BufferedOutputStream(file);
        DataOutputStream data = new DataOutputStream(buff);

        for (int i = 0; i < 400; i++)
            data.writeInt(i);
        data.close();
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

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

    // create new file output stream
    FileOutputStream fos = new FileOutputStream("C://test.txt");

    // get file descriptor instance
    FileDescriptor fd = fos.getFD();

    // test if the file is valid
    boolean bool = fd.valid();

    // print/*from   w  w w. ja  v a 2  s  .  c  o m*/
    System.out.print("Is file valid? " + bool);

}

From source file:Main.java

License:asdf

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

    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"), "8859_1"));
    out.write("asdf");
    out.close();//from   w  w w .  j  a va2  s .co  m
}