• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File Operations Program Problem

 
Greenhorn
Posts: 15
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi friends,
I have written a program using thread and I/O operations which should read all the text files from a folder and should retrieve the values(Files contains organized records) and insert into the database table.When the data of a file is read and inserted to the database,the file should be deleted from that folder,if any exception occurs,the file should be moved to a folder called "Error".In my program all the things are going fine,but after reading the file and inserting,the file is not getting deleted,and also the error file is not moved to the error folder...Can anyone please help me out with a solution as quick as possible...Below is my code,,,
package com.thread.fileprocessingwithdatabase.exam;



[Edit - added code tags - see UseCodeTags for details]
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags (⇐click) so that your code will be readable.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun ck wrote:


Well, the problem with the move operation seems pretty obvious
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code that opens and closes the file looks a little suspect as well. You open a FileInputStream (line 44) and wrap it in a DataInputStream (line 45) but you only close the FileInputStream (line 75). The reason you can't delete the file may be because the OS thinks your DataInputStream still has the file open.
 
Arun vel
Greenhorn
Posts: 15
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Thanks for your reply,
I have tried closing the DataInoutStream and also I have tride in differrent ways to solve this.Btu I am not able to correct.Can you please help me out with a solution.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Print out the value of files[i] after line 43 and print out the value of fileName after line 80. Then try and work out why they are different.
Hints - on line 47 what does File.getName return ? What happens when you create a new File object using only a file name (no directory path) ?
 
Arun vel
Greenhorn
Posts: 15
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks Joanne Neal..I have cleared that..
 
Arun vel
Greenhorn
Posts: 15
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..Now I want to store all the names of the files which I have processed in the above program in an arraylist..I dont know how to do..
It is for the purpose of checking for the duplicate files..
The names should be permanently stored in an arraylist..
Can anyone please help..
 
reply
    Bookmark Topic Watch Topic
  • New Topic