I am attempting to edit a file called groups by adding a username to it. My code reads the file with filereader. Each line is readin, and searched for the group (foreign in this case). Then "foreign username," is substituted into the string for foreign. Then the file is written. The result is the groups file shows just null in it. My Code is below, any help on this would be greatly appreciated. Thanks
try { String username = "tree_l"; String group = "foreign"; File grp = new File("/home/ejantk_a/temp/groups"); FileReader raf = new FileReader(grp); BufferedReader in = new BufferedReader(raf); String line; //Search for group name, and replace with group name plus username. while((line = in.readLine()) != null) { Perl5Util perl = new Perl5Util(); if(perl.match("/" + group + "/", line)) { line = perl.substitute("s/" + group + "/($1) " + username + ", /", line); } } //Write to File Object. FileWriter fw = new FileWriter(grp); PrintWriter pw = new PrintWriter(fw); pw.println(line); fw.close(); } catch (IOException e) { System.out.println("Error -- " + e.toString()); } ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html