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 FileNotFoundException, UnsupportedEncodingException { Formatter formatter = new Formatter(new FileOutputStream("generated/format.txt"), "ASCII"); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string System.out.println(formatter); // flush the formatter. Here it does nothing. formatter.flush();/*from w w w . j a v a2 s . co m*/ System.out.println("Formatter Flushed."); }
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);//from w w w. j a v a2 s . co m oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print from index 0 to 7 byte[] b = new byte[13]; ois.readFully(b, 0, 7); String array = new String(b); System.out.println(array); ois.close(); }
From source file:Main.java
static public void main(String args[]) throws Exception { FileInputStream fin = new FileInputStream("infile.txt"); FileOutputStream fout = new FileOutputStream("outfile.txt"); FileChannel inc = fin.getChannel(); FileChannel outc = fout.getChannel(); ByteBuffer bb = ByteBuffer.allocate(1024); while (true) { int ret = inc.read(bb); if (ret == -1) break; bb.flip();// w w w .j a va2 s. c om outc.write(bb); bb.clear(); } }
From source file:Main.java
static public void main(String args[]) throws Exception { FileInputStream fin = new FileInputStream("infile.txt"); FileOutputStream fout = new FileOutputStream("outfile.txt"); FileChannel inc = fin.getChannel(); FileChannel outc = fout.getChannel(); ByteBuffer bb = ByteBuffer.allocateDirect(1024); while (true) { int ret = inc.read(bb); if (ret == -1) break; bb.flip();//from www . jav a 2 s .c om outc.write(bb); bb.clear(); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;//ww w . j a v a 2s. co m int i = 0; FileOutputStream fos = new FileOutputStream(FileDescriptor.out); fos.write(b); fos.flush(); FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } fos.close(); fis.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { FileInputStream inFile = new FileInputStream(args[0]); FileOutputStream outFile = new FileOutputStream(args[1]); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); inChannel.close();//from w w w . ja va2s . co m outChannel.close(); }
From source file:HelloWorldRtf.java
public static void main(String[] args) { try {//from w w w.j av a2 s .c o m Document document = new Document(); RtfWriter2.getInstance(document, new FileOutputStream("HelloWorldRtf.rtf")); document.open(); document.add(new Paragraph("Hello World!")); document.close(); } catch (Exception e) { e.printStackTrace(); } }
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();/* w w w . j av a 2s. c om*/ writer.addJavaScript("this.print(false);", false); document.add(new Paragraph("iText")); document.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(new Example()); oout.flush();/* w ww . j av a2s.com*/ oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); Example a = (Example) ois.readObject(); System.out.println(a.s); ois.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { FileChannel fc = new FileOutputStream("data2.txt").getChannel(); fc.write(ByteBuffer.wrap("Some text".getBytes("UTF-16BE"))); fc.close();//from w w w. j av a2 s. c o m ByteBuffer buff = ByteBuffer.allocate(BSIZE); // Now try reading again: fc = new FileInputStream("data2.txt").getChannel(); buff.clear(); fc.read(buff); buff.flip(); System.out.println(buff.asCharBuffer()); }