Posts

Showing posts from April 4, 2011

Program in java to create file in byte mode

import java.io.*; class ByteModeFile { public static void main (String[] args)  throws Exception {         System.out.println("Enter the name of file");              DataInputStream c=new DataInputStream(System.in);              String name=c.readLine();     FileOutputStream fout =new FileOutputStream(name); String n=" "; StringBuffer sb=new StringBuffer(1024); try {         while(n!=null)         {         n=c.readLine();         sb.append(n);     } } catch (Exception ex) {     System.err.println("Error "  );     ex.printStackTrace(); } finally {     fout.write(new String(sb).getBytes());     fout.close(); } } ...

Program in java to copy files using command line argument

import java.io.*; class Copy { public static void main (String[] args) throws Exception { FileReader fin=new FileReader(args[0]); FileWriter fout=new FileWriter(args[1]); byte[] buffer =new byte[1024]; int i=0; while(i!=-1) { i=fin.read(); fout.write(i); } fin.close(); fout.close(); System.out.println("File copied "); } }