List of usage examples for java.io FileOutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this file output stream. From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("test.txt", true); fos.write("Appended".getBytes()); fos.close();/*from w ww.j a va 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/demo.txt", true); fos.write("Appended".getBytes()); fos.close();/*from w ww. j a v a 2s.co m*/ }
From source file:Test.java
public static void main(String[] args) throws Exception { Lock myLock = new ReentrantLock(); Random random = new Random(); myLock.lock();/*from ww w.j a v a2s . c om*/ int number = random.nextInt(5); int result = 100 / number; System.out.println("A result is " + result); FileOutputStream file = new FileOutputStream("file.out"); file.write(result); file.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { String url = "http://www.java2s.com/style/download.png"; String text = "java2s.com"; byte[] b = mergeImageAndText(url, text, new Point(200, 200)); FileOutputStream fos = new FileOutputStream("new.png"); fos.write(b); fos.close();// w ww . j a v a 2s .c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/demo.txt"); byte b = 01;//from w w w .j av a 2s.c o m fos.write(b); fos.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); File file = null;// w ww. ja v a 2s. co m byte[] buf = cert.getEncoded(); FileOutputStream os = new FileOutputStream(file); os.write(buf); os.close(); Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write(new sun.misc.BASE64Encoder().encode(buf)); wr.flush(); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 65, 66, 67, 68, 69 }; int i = 0;//from www . j av a2s . co m FileOutputStream fos = new FileOutputStream("C://test.txt"); fos.write(b); // flushes the content to the underlying stream fos.flush(); // create new file input stream 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); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b[] = { 65, 66, 67, 68, 69 }; FileOutputStream fos = new FileOutputStream("C://test.txt"); fos.write(b); // pushes stream content to the underlying file fos.flush();/*from w ww .jav a 2 s.com*/ // returns file channel associated with this stream FileChannel fc = fos.getChannel(); // returns the number of bytes written long pos = fc.position(); System.out.print(pos); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;/*from w w w . j a v a2s. co m*/ int i = 0; FileOutputStream fos = new FileOutputStream("C://test.txt"); 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); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;/*from w ww.j a va 2 s . c o m*/ int i = 0; FileOutputStream fos = new FileOutputStream("C://test.txt", true); 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); } }