java - Problems with importing a document and changing the strings of the document and outputting the new strings in a new .txt document -
it should output new .txt document, when does, outputs original document. error message:
exception in thread "main" java.lang.error: unresolved compilation problem: method must return result of type string
if comment out return "ok", otherwise creates new document same details original document.
what cause?
public static string replace(string filename) { try { scanner file = new scanner(new file(filename)); system.out.println(file); stringbuilder b = new stringbuilder(); string s = ""; while(file.hasnextline()){ s = file.nextline(); if (s.equals("x")) { s = "0"; b.append(s).append(system.getproperty("line.separator")); } else { b.append(s).append(system.getproperty("line.separator")); } } try (printstream out = new printstream(new fileoutputstream("test1,1.txt"))) { out.print(b); out.close(); } catch (ioexception e) { } } catch (exception e) { system.out.println("problem reading file."); } return "ok"; }
Comments
Post a Comment