Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically add text files in a given directory, in Java?

Tags:

java

I am using Eclipse. I want to read number of XML files from a directory. Each XML file contains multiple body tags. I want to extract values of all the body tags. My problem is I have to save each body tag value (text) in a separate .txt file and add these text files in another given directory. Can you plz help how can I create dynamically .txt file and add them in a specified directory? Thanks in advance.

like image 250
Vinita Avatar asked Feb 17 '11 08:02

Vinita


1 Answers

First specify directory path and name

File dir=new File("Path to base dir");
if(!dir.exists){
dir.mkdir();}

//then generate File name

String fileName="generate required fileName";
File tagFile=new File(dir,fileName+".txt");
if(!tagFile.exists()){
tagFile.createNewFile();
}
like image 187
Feras Odeh Avatar answered Sep 21 '22 14:09

Feras Odeh