添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I’m trying to delete a CSV file that has red by CSVReader object (comes with opencsv library). End of the file reading process, I wanted to delete it. So I’m trying it with f.delete(); (f is the file object) but It doesn’t working for some times. The CSVREader object has correctly closed with reader.close(); .

I have tried this with a test java class and I deletes successfully .

File f = new File(“E:\\LogData\\NewGlog_0001_20140202191120.csv”);
f.delete();

I feel it is a problem with the openCSV. plz help me.

Thank in advance.

First, check your write permissions on the file (e.g. with f.canWrite())

If you read a file you should then close it. Otherwise it stays in use.

Make sure reading the csv file has been handled properly, i.e.

try (Reader reader = openReader(..)) {

If you need it to remain open, you can use file.deleteOnExit() which will delete the file whenever the VM is shut down.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.