Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written a java code to merge all the CSV files and save the data in a single file. I have to save the merged file in a separate directory and delete the other files. The code works fine but i am not able to move the merged file to another directory. I have tried using renameTo , writing file to another directory but only an empty file gets moved. Could you please help? It would be helpful if a code snippet is provided. Thankyou in advance.
Posted

1 solution

Keep trying, turn on your brain. I am serious.

The bug must be so trivial that you certainly should fix it by yourself, if you want learn at least the very basics of programming. You did not show your code with the bug, but even if we knew what to fix, it would be a bad help for you. Don't loose your change to get the very basic skills. Such file chores are among the most primitive ones; if you don't overcome them all by yourself, you would not do anything in programming.

I you feel frustrated, think again. I want to encourage you, not frustrate. Tell yourself "I can do it".

—SA
 
Share this answer
 
Comments
Member 11226682 13-Jan-15 0:19am    
I have been trying so many solutions for the past one week. Nothing seems to strike. Code just works fine. The merged file is empty when i move it to another directory.
This is the code snippet where the data is appended and sent to another directory.

private void readAndAppend() //reading the files and appending them
{
File fileOut = new File(this.directory, fileName); //new input
//fileOut.delete();
if (fileOut.exists())
{
fileOut.delete();
} // end if block
//creation of the appended file
try
{
fileOut.createNewFile();
System.out.println("File: '" + fileOut.getAbsolutePath() + "' created successfully");
fileOut.renameTo(new File("Directory to which the merged file is sent" + fileOut.getName()));
} //ends try block
catch (IOException err )
{
err.printStackTrace(System.err);
} // ends catch block
Sergey Alexandrovich Kryukov 13-Jan-15 0:20am    
Don't try. No guesswork needed. Think.
—SA
Sergey Alexandrovich Kryukov 13-Jan-15 0:21am    
Checkup if path delimiter between path and simple file name is missing. Use the debugger.
—SA
Member 11226682 13-Jan-15 0:27am    
Fine. Thank You.
Member 11226682 13-Jan-15 0:36am    
No messages are shown in the debuuger. Checked with delimiters. Looks fine. If i don't move the merged file to another directory then i can view the data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900