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:MainClass.java
public static void main(String[] args) throws Exception { String password = "password"; KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(1024);//from w w w . j a v a2 s . com KeyPair keyPair = keyPairGenerator.genKeyPair(); String publicKeyFilename = "public"; byte[] publicKeyBytes = keyPair.getPublic().getEncoded(); FileOutputStream fos = new FileOutputStream(publicKeyFilename); fos.write(publicKeyBytes); fos.close(); String privateKeyFilename = "privateKeyFilename"; byte[] privateKeyBytes = keyPair.getPrivate().getEncoded(); byte[] encryptedPrivateKeyBytes = passwordEncrypt(password.toCharArray(), privateKeyBytes); fos = new FileOutputStream(privateKeyFilename); fos.write(encryptedPrivateKeyBytes); fos.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.dat"); InflaterInputStream iis = new InflaterInputStream(fin); FileOutputStream fout = new FileOutputStream("b.dat"); for (int c = iis.read(); c != -1; c = iis.read()) { fout.write(c); }//from w ww . j a v a2s .c o m fout.close(); }
From source file:CopyBytes.java
public static void main(String[] args) throws IOException { File inputFile = new File("input.txt"); File outputFile = new File("output.txt"); FileInputStream in = new FileInputStream(inputFile); FileOutputStream out = new FileOutputStream(outputFile); int c;/*from w ww . ja v a 2s.co m*/ while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String strFilePath = "C://demo.txt"; FileOutputStream fos = new FileOutputStream(strFilePath); String strContent = "Write File using Java FileOutputStream example !"; fos.write(strContent.getBytes()); fos.close();/*from w ww. j a v a2s. c o m*/ }
From source file:Main.java
public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("C://text.txt"); fos.close();/* www.java2s. c o m*/ // try to write into underlying stream fos.write(65); fos.flush(); fos.close(); }
From source file:Base64Decode.java
/** * A test method of questionable utility. *//* w ww .j av a 2 s .co m*/ public static void main(String args[]) { try { FileOutputStream fos = new FileOutputStream("out.dat"); fos.write(decode(System.in)); fos.close(); } catch (IOException ie) { ie.printStackTrace(); } }
From source file:FileOutputStreamDemo.java
public static void main(String args[]) throws Exception { FileOutputStream fos = new FileOutputStream(args[0]); // Write 12 bytes to the file for (int i = 0; i < 12; i++) { fos.write(i); }/*from w ww. j a v a2 s . c om*/ // Close file output stream fos.close(); }
From source file:Hex.java
public static void main(String[] args) { if (args.length != 3) { System.out.println("Usage: HexStrToBin enc/dec <infileName> <outfilename>"); System.exit(1);// w w w . j a v a 2 s. c o m } try { ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream in = new FileInputStream(args[1]); int len = 0; byte buf[] = new byte[1024]; while ((len = in.read(buf)) > 0) os.write(buf, 0, len); in.close(); os.close(); byte[] data = null; if (args[0].equals("dec")) data = decode(os.toString()); else { String strData = encode(os.toByteArray()); data = strData.getBytes(); } FileOutputStream fos = new FileOutputStream(args[2]); fos.write(data); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) { FileInputStream fin = new FileInputStream(args[i]); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null;/*ww w . j a va 2 s . co m*/ while ((ze = zin.getNextEntry()) != null) { System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } zin.close(); } }
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)); outStream.close();/*from w w w .ja v a2 s. c om*/ 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(); }