Unable to modify a file entered as an argument JAVA -
i'm trying work doesn't , don't why, it's supposed script enter argument file , replaces correct replaced characters in it. doesn't replace file entered argument. can work if place whole code in main function without calling method.
thanks.
public class rename { public static void main(string[] args) throws ioexception{ file origine = new file(args[0]); renamefile(origine); } public static void renamefile(file fileoriginal) throws ioexception { try { file tempfile = file.createtempfile("buffer", ".tmp"); filewriter fw = new filewriter(tempfile); reader fr = new filereader(fileoriginal); bufferedreader br = new bufferedreader(fr); while (br.ready()) { fw.write(br.readline().replace("#/a#" , "Á")); } fw.close(); br.close(); fr.close(); tempfile.renameto(fileoriginal); } catch (ioexception e) { e.printstacktrace(); } } }
renameto()
returns value. ignoring it.- you can't rename file name of existing file. have ensure target name doesn't exist.
ready()
not test end of stream: see javadoc.- a method modifies content of file should not called
renamefile()
.
Comments
Post a Comment