Here you can find the source of copyFile(String fromFilePath, String toFileDir)
Parameter | Description |
---|---|
fromFilePath | a parameter |
toFileDir | a parameter |
public static String copyFile(String fromFilePath, String toFileDir)
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main { /**//ww w.j a va 2 s. c o m * Copies a file, located at fromFilePath into toFileDir. * File name remains the same. * @param fromFilePath * @param toFileDir */ public static String copyFile(String fromFilePath, String toFileDir) { FileReader inputStream = null; FileWriter outputStream = null; String copiedFileName = (new File(fromFilePath)).getName(); String toFilePath = toFileDir + "/" + copiedFileName; try { inputStream = new FileReader(fromFilePath); outputStream = new FileWriter(toFilePath); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } return toFilePath; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }