java - Trying to get Scanner to scan entire file -
string userinput = stdin.nextline(); file = new file(userinput); scanner filescanner = new scanner(file); while(filescanner.hasnext()) { filecontents = filescanner.nextline(); } so i'm trying figure out how can variable filecontents hold of file scanner. current way have setup variable filecontents left last line of .txt file. i'm doing need hold entire text file. spaces, chars , all.
i'm sure there simple fix i'm new java/coding.
you need change
filecontents += filescanner.nextline(); or
filecontents =filecontents + filescanner.nextline(); with approach reassigning filecontents value instead need concat next line.
Comments
Post a Comment