d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Input And Output Files
Add Reply New Topic New Poll
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Mar 27 2016 07:55pm
I'm trying to create multiple output files based off an input file where the file names in the input file can vary and can be repeated in which case the text would just be added to the already created file

example input file
Code
outputfile1.txt
hello
outputfile2.txt
abcd
outputfile3.txt
xyz
outputfile1.txt
how are you


whats the best way to go about this not looking for code just some direction thanks
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 27 2016 08:01pm
what part do you have issues with?

/edit

open input file.
read all the file names into an array.
loop the array.
open the file with append mode true.

This post was edited by carteblanche on Mar 27 2016 08:04pm
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Mar 27 2016 08:09pm
Quote (carteblanche @ Mar 27 2016 09:01pm)
what part do you have issues with? read in the file name. open the file with append mode true.


so I can just loop through the input file, set the file name to a String and what do something like PrintWriter writer = new PrintWriter(fileName);?
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 28 2016 12:46am
you need to write to a filewriter to append
PrintWriter writer = new PrintWriter(new FileWriter(fileName,true));//true sets append mode on
filewriter is costly though look into bufferedwriter as well new printwriter(new bufferedwriter(new filewriter(file,true)))
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Mar 28 2016 07:25pm
thanks to both of you guys

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll