I am sorry I dont have a code, I say in a few answers how to make a file and write to it, but I have another question. I give a path to a folder in my compilation, and I want for each file that ends with a .jack to create the same file name that ends with .xml
and open the xml file and write to it. exemple:
start.jack
bet.jack
=>
start.xml
bet.xml
and in each xml file I would like to write stuff according whats written in the jack file.
so actually I need to open the jack file, read from it, and then write to the xml file itself.
I hope I explained myself correctly.
My Code:
public String readFile(String filename)
{
String content = null;
File file = new File(filename);
try {
FileReader reader = new FileReader(file);
char[] chars = new char[(int) file.length()];
reader.read(chars);
content = new String(chars);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
I took this lines from stackoverflow, and it worked perfectly