Exception error of "main" java.util.NoSuchElementException -
i have these below 2 classes , trying trying run app class can take command line arguments instead of having fixed file name in code
when execute code, following errors:
c:\javatest>java readfiletestapp resume.doc exception in thread "main" java.util.nosuchelementexception @ java.util.scanner.throwfor(unknown source) @ java.util.scanner.next(unknown source) @ readfile.getfile(readfile.java:26) @ readfiletestapp.main(readfiletestapp.java:8)
import java.io.file; import java.util.scanner; import java.io.filenotfoundexception; public class readfile { private string filename = ""; private long maxsize = 102400; readfile(){}; readfile(string filename, long maxsize) { this.filename = filename; this.maxsize = maxsize; } public string getfile() throws filenotfoundexception { file file = new file(this.filename); if (file.exists()) { double filesize = file.length(); if (filesize > this.maxsize) { return "file larger max size"; } else if (filesize == 0) { return "file empty"; } else { string filecontents = new scanner(file).usedelimiter("\\z").next(); return filecontents; } }else { return "file not found!"; } } } import java.io.filenotfoundexception; public class readfiletestapp extends readfile { public static void main(string [] args) throws filenotfoundexception { readfile rf = new readfile(args[0], (long) 102400); system.out.println(rf.getfile()); } }
Comments
Post a Comment