public class FileIOTest{
public void copyFile ( String filePath ) {
int len = 0 ;
FileInputStream fis = null ;
FileOutputStream fos = null ;
File file = new File(filePath) ;
try{
fis = new FileInputStream( filePath ) ;
String newFileName = file.getPath().replaceAll("\\.txt", ".xxx");
fos = new FileOutputStream( new File( newFileName ) );
byte[] bt = new byte[1024];
while ( ( len = fis.read( bt )) != -1){
fos.write( bt , 0 , len );
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
fis.close();
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main (String args[]) throws Exception {
FileIOTest ft= new FileIOTest() ;
ft.copyFile("D:\\111.txt");
}
}