I am currently working on an encounter generator for a pen and paper rp game known as D&D(Dungeons and dragons). I have an archive of monsters written in notepad files. When the user is finished using the filters he wants and presses "generate" the program filters through the monsters, reads the notepad file with the given monster(s) and writes it(them) to a new notepad file which is then opened (using runnable exec). This all worked as intended when I read and wrote from notepad to notepad. Then I received some feedback from my testers that they would like some pictures as well as a different formating of the text. Therefore i changed the archive files to RTF (word pad / rich text file) and also changed the finished file to the same format. My problem now, is that the program only writes one monster to the file even if its supposed to write two or more.
Here is the code for the reader and writer method
public void readerAndWriter()throws IOException
{
destination = "Encounter.rtf";
File EncounterFile = new File(source);
FileInputStream fis =new FileInputStream(EncounterFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
FileWriter writer = new FileWriter(destination,true);
BufferedWriter out = new BufferedWriter(writer);
String aLine = null;
while((aLine = in.readLine())!= null)
{
out.write(aLine);
out.newLine();
}
in.close();
out.close();
}
Here is the code snippet for the method that is using the reader and writer method
if (monsters.get(t).getRace() == monsters.get(u).getRace())
{
if (monsters.get(t).getCr() + monsters.get(u).getCr() ==
getChosenCr())
{
readAndWrite.setSource(monsters.get(t).getFilePath());
readAndWrite.readerAndWriter();
readAndWrite.setSource(monsters.get(u).getFilePath());
readAndWrite.readerAndWriter();
correctMonster = true;
}
else
etc etc
all tips and hints are appreciated.