List of usage examples for java.io FileOutputStream FileOutputStream
public FileOutputStream(FileDescriptor fdObj)
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/demo.txt"); FileOutputStream fos = new FileOutputStream(file); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream(new File("C:/Demo")); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write("this is a test".getBytes()); bos.flush();/* w ww . j av a 2 s . c o m*/ bos.close(); }
From source file:BufferedOutputStreamDemo.java
public static void main(String args[]) throws Exception { FileOutputStream fos = new FileOutputStream(args[0]); BufferedOutputStream bos = new BufferedOutputStream(fos); // Write 12 bytes to the file for (int i = 0; i < 12; i++) { bos.write(i);/*from www .j av a 2s . c o m*/ } bos.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . j a v a2 s . c o m // create a new OutputStreamWriter OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(70); // flush the stream writer.flush(); // read what we write System.out.println((char) in.read()); writer.close(); os.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] vals = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 }; FileOutputStream fout = new FileOutputStream("Test.dat"); for (int i = 0; i < vals.length; i += 2) fout.write(vals[i]);/* ww w.j av a2 s . c om*/ fout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/MyZip.zip"); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze = new ZipEntry("C:/file1.txt"); zos.putNextEntry(ze);/*from w w w. j a v a 2 s .co m*/ zos.closeEntry(); ze = new ZipEntry("C:/file2.txt"); zos.putNextEntry(ze); zos.closeEntry(); zos.close(); }
From source file:Main.java
public static void main(String[] args) { char[] arr = { 'H', 'e', 'l', 'l', 'o' }; try {//w w w. j a v a2 s. c o m OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(arr, 0, 3); // flush the stream writer.flush(); // read what we write for (int i = 0; i < 3; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedOutputStream bufferedOutput = new BufferedOutputStream(new FileOutputStream("yourFile.txt")); bufferedOutput.write("Line one".getBytes()); bufferedOutput.write("\n".getBytes()); bufferedOutput.write(65);/*w w w . j av a2 s .c o m*/ bufferedOutput.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String strFilePath = "C:/Double.txt"; FileOutputStream fos = new FileOutputStream(strFilePath); DataOutputStream dos = new DataOutputStream(fos); double d = 1; dos.writeDouble(d);/*from w w w .jav a 2 s . c o m*/ dos.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileOutputStream fos = new FileOutputStream("test"); MessageDigest md = MessageDigest.getInstance("SHA"); ObjectOutputStream oos = new ObjectOutputStream(fos); String data = "thee"; byte buf[] = data.getBytes(); md.update(buf);/*from www . ja v a 2s . c o m*/ oos.writeObject(data); oos.writeObject(md.digest()); }