java - Need help reading files -


i'm writing mock stock market in java, , want ability user view stocks purchased. decided easiest way write file. problem every time run program , attempt read file, outputs path took read it. information want correctly written file, isn't reading way want.

here code used file reading section:

if (amountofstocks1 >= 1) {   scanner stocksbought1 = new scanner("stocksbought/stocksbought1.txt");    while (stocksbought1.hasnext()) {     string fileread = stocksbought1.nextline();     system.out.println(fileread);   }   stocksbought1.close();   runmenu = 1; } 

there 7 of these amountofstocks if/else statements.

i'm not sure if that's enough information. if it's not, tell me put on, , i'll that.

if can me fix problem or if know easier way read , write files great!

instead of:

scanner stocksbought1 = new scanner("stocksbought/stocksbought1.txt"); 

try:

scanner stocksbought1 = new scanner(new file("stocksbought/stocksbought1.txt")); 

when pass string scanner constructor scanner scans string. if give file scan contents of file.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -