Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to copy file from directory to another Directory in Java
    primarykey
    data
    text
    <p>I am using <code>JDK 6</code>.</p> <p>I have 2 folders names are <code>Folder1</code> and <code>Folder2</code>.</p> <p><code>Folder1</code> have the following files</p> <pre><code>TherMap.txt TherMap1.txt TherMap2.txt </code></pre> <p>every time <code>Folder2</code> have only one file with name as <code>TherMap.txt</code>.</p> <p>What I want,</p> <p>copy any file from <code>folder1</code> and pasted in <code>Folder2</code> with name as <code>TherMap.txt</code>.If already <code>TherMap.txt</code> exists in <code>Folder2</code>, then delete and paste it.</p> <p>for I wrote the following code.but it's not working</p> <pre><code>public void FileMoving(String sourceFilePath, String destinationPath, String fileName) throws IOException { File destinationPathObject = new File(destinationPath); File sourceFilePathObject = new File(sourceFilePath); if ((destinationPathObject.isDirectory()) &amp;&amp; (sourceFilePathObject.isFile())) //both source and destination paths are available { //creating object for File class File statusFileNameObject = new File(destinationPath + "/" + fileName); if (statusFileNameObject.isFile()) //Already file is exists in Destination path { //deleted File statusFileNameObject.delete(); //paste file from source to Destination path with fileName as value of fileName argument FileUtils.copyFile(sourceFilePathObject, statusFileNameObject); } //File is not exists in Destination path. { //paste file from source to Destination path with fileName as value of fileName argument FileUtils.copyFile(sourceFilePathObject, statusFileNameObject); } } } </code></pre> <p>I call the above function in <code>main()</code></p> <pre><code> //ExternalFileExecutionsObject is class object ExternalFileExecutionsObject.FileMoving( "C:/Documents and Settings/mahesh/Desktop/InputFiles/TMapInput1.txt", "C:/Documents and Settings/mahesh/Desktop/Rods", "TMapInput.txt"); </code></pre> <p>While I am using <code>FileUtils</code> function, it showing error so I click on error, automatically new package was generated with the following code.</p> <pre><code> package org.apache.commons.io; import java.io.File; public class FileUtils { public static void copyFile(File sourceFilePathObject, File statusFileNameObject) { // TODO Auto-generated method stub } } </code></pre> <p>my code not showing any errors,even it's not working.</p> <p>How can I fix this.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload