Home
> Java > Java Program to read data from file through inputfilestream and write its contents on another file through fileoutputstream – Q35
Java Program to read data from file through inputfilestream and write its contents on another file through fileoutputstream – Q35
Q35: Java Program to read data from file through inputfilestream and write its contents on another file through fileoutputstream.
import java.io.*; import javax.swing.*; class File_RW{ public static void main(String args[]) throws IOException{ String f_name = JOptionPane.showInputDialog("Enter a file name: "); InputStream infile = new FileInputStream(f_name); int fsize = infile.available(); f_name = JOptionPane.showInputDialog("Enter a file name to Save As: "); OutputStream outfile = new FileOutputStream(f_name, true); System.out.println("Reading File : " + f_name + "\n"); char ch; for(int i=0; i<fsize; i++){ ch = (char)infile.read(); outfile.write(ch); System.out.print(ch); } infile.close(); outfile.close(); System.out.println("File Successfully Copied."); } }
… from College notes (BCA/MCA assignments):
Categories: Java
Java File Handling, Java IO Programs
Comments (0)
Trackbacks (0)
Leave a comment
Trackback