File Copy

import java.io.*
class CopyFile
{
int ch;
//reading data from args[0]
FileInputStream fin=new FileInputStream(args[0]);
// for writing data into args[1]
FileOutputStream fout=new FileOutPutStream(args[1]);
while(ch=fin.read()!=-1){
fout.write(ch);
}
fin.close();
fout.close();
}
}

Reading a File using FileReader

import java.io.*
class ReadFile
{
public static void Main(String[] args) throws IOException{
int ch;

// check if file exist or not
FileReader fr=null;
try{
fr= new FileReader("TestFile")
}catch(Exception e){
System.out.println("File Not Found");
return;
}
// read the file till end of the file
while(ch=fr.read()!=-1){
System.out.print((char)ch);
//close the file
fr.close();
}
}

Creating a File Using File Writer

import java.io.*
class CreateFile
{
public static void Main(String[] args) throws IOException{
String text="This is The File Content on Java" + "\n i am writing This in the
File";
// Attach a file to FileWriter
FileWriter fw=new FileWriter("TestFile");
// read the character wise from string and write into file
for(int i=0;i fw.write(text.charAt(i));
//close the file
fw.close();
}
}

To Save Image By Using Image

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/*
* @Author : Spice
* You Should give a File path to save
*/
public class SaveImage {
public static String stt;

public static void saveImage(File fileToSave )
{

// String stt=ImagePanel.pathname;
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(stt);
to = new FileOutputStream(fileToSave);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead);// write
to.close();
}catch(NullPointerException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}

}