0

Reading from one file, I need to create logs with the names that are in the file. To do that I put the names from the first file into an array and used PrintWriter to create files to write in. So the names are in an array called names. My code is

i=0;
PrintWriter [] log_name= new PrintWriter[numberofnames];
while (i != numberofnames){
    log_names[i]=new PrintWriter("log_"+names[i]+".txt");
    i += 1;
}

The problem is, I need refer to specific logs with specific names. So if I know that I have to refer to a log with the a specific name, how would I refer to that log to write into it?

I was thinking that I could do something like this:

String newname="John";
log_newname.println("the message");

but I don't think log_newname would be the same log as the one I named earlier.

user207421
  • 305,947
  • 44
  • 307
  • 483
pumpkin
  • 57
  • 4
  • I don't understand this on multiple levels. First, you're naming a file `"log_names[i].txt"`, you're not creating multiple filenames. Second, you *do* know the log file names, because you're trying to create them. Without knowing the specific goal it's difficult to speculate, but it seems like you either need a map of names to log file names, or just the `File`s themselves, or you can create it on-the-fly. – Dave Newton Jun 13 '15 at 19:48
  • I edited it to fix the log_names[i].txt – pumpkin Jun 13 '15 at 21:39

0 Answers0