My error (see my comment below) only occurs when I have only 1 number, 1 first name, and 1 last name. When I added more numbers and names to my file, it printed out the correct stuff.
I'm getting an error involving my readFile method:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at readfile.readFile(readfile.java:24) --> This line is the declaration of c.
at apples.main(apples.java:5) --> This line calls the method readFile.
Say I read a number from a file -- how would I add those numbers together? I saved the read data as int variables but for some reason I get an error "unexpected type" when they should be treated as regular variables.
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at H81_reading_from_file.readfile.readFile(readfile.java:27) at H81_reading_from_file.apples.main(apples.java:9)
Sorry, The Program Could Not Find The File Specified.
Exception in thread "main" java.lang.NullPointerException at readfile.readFile(readfile.java:16) at launcher.main(launcher.java:6) ?!?!?!?!?!?!?!?!??!!?!?!?!?!?!?!?!?!?! I copied this exactly -.-
@nWANTED yes this is far better compared to hasNext() because you read the whole line it is not confusing is it like wen u print the whole line, println but i think hasNext() is good to cover first in tutorial. java must be having many methods to read a file i guess.
it think we should put the try catch in the main too. When i trigger the error in the readfile class, it catch it but then the open read and close from the main class display errors too.
I have a small question. If the hasNext() method in the while returns only if there is still at least one token to read, but you use 3 tokens in a row on your code without rechecking with hasNext(), wouldn't it cause problems?
if you wanted to keep the values for a,b, and c so that you keep everything read from the file, you'ld use arrays a[] b[] c[] (with appropriate sizes) and iterate through each element in the arrays. You could then do a search a name or number or whatever you want to do with the data.
can someone pllzzzz tell me how can i handle the context of a file? for example lets say taht i want to find someone whith his last name and print his age . :( plzzz
Hey bucky i was just wondering how does the method x.next() know to assign each part of the record first to a, then b, and then to c. I just thought if you're assigning x.next() to all three a, b , and c wouldn't all of them be the same?
@sebg18 I believe it's because the spaces separates them. It reads the text and goes on to the "next()" part of the document with text in it. (Might wanna look that up to confirm it, but from what I've tested, that's true.)
@stargem16 make a new file using formater(tutorial 79 if i remeber right) ... read the data from the first file (this one)... write them in the second(tutorial 80) wish that helped
@MurayTheBanana check his 80th tutorial on how to write to files and his 75th / 76th (I think) tutorials on how to register x and y positions with the mouse. 1 + 1 = 2:p
Just store those positions in the text file and you're done ;) load em whenever you like
@ bucky , if u read this there's in issue about this tutorial , a couple of us have been havin , its posted in ur java forum , can u please check it out .
Thank you so much Bucky! I really appreciate these Tutorials. You've helped me out with my programming class and its rly coming in handy this last part of the year. Thank you so much i really appreciate it ! :D
Thanx Bucky for everything. awesome tutorials. I have a doubt. what if we want to read suppose all XML files. does "*.xml" does work ???? Thanx in advance.
dude, i'm the kind of person, that uderstand way more if someone explain me, than reading the example, thnx, you are a great help, i need something like this for my project.
I hear crickets in the background. Are you programming in the woods? Right on!
dropbows90 1 day ago
can you use this same method to read a Config file?
nitricdx 4 days ago
How can I open a file that i have created with Formatter to store more values???
raheelbutt92 1 month ago
My error (see my comment below) only occurs when I have only 1 number, 1 first name, and 1 last name. When I added more numbers and names to my file, it printed out the correct stuff.
lNUMPUN 2 months ago
I'm getting an error involving my readFile method:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at readfile.readFile(readfile.java:24) --> This line is the declaration of c.
at apples.main(apples.java:5) --> This line calls the method readFile.
lNUMPUN 2 months ago
My program NEVER writes, what's in the class. I tried many things but nothings working. can so help?
Genuigr 2 months ago in playlist Java Programming Tutorials
Say I read a number from a file -- how would I add those numbers together? I saved the read data as int variables but for some reason I get an error "unexpected type" when they should be treated as regular variables.
Tinzert 2 months ago
@Tinzert Store it in a variable and then convert it to a int, make temp variables to add them!
QuantumSicarius 2 months ago in playlist Java Programming Tutorials
@Tinzert
int sum=0;
while(x.hasNextInt){
sum+=x.nextInt();
}
gatoo23 2 months ago
"Joe Doe". This is why I watch your Java tutorials, Bucky.
bace1000 3 months ago in playlist More videos from thenewboston
My name's Mike Ike.
HomicidaMortis 3 months ago
What do you do if the file is a table with some blank elements. so like
a b c
0 3
3 4 5 3 4
so how do I make sure that it only puts in a, b or c the values in their respective columns, anyone know?
chevon1920 3 months ago
How do you get multiple records? everytime I run mine it just replaces the first one with the new one
JKTCGMV13 3 months ago in playlist Java Programming Tutorials
Is there a method for updating files in java?
tmovjesca 4 months ago in playlist More videos from thenewboston
why doesnt it recognise symbol Scanner???
INTERNAL_ASSESSMENT/Internal_Assessment_18_10.java [215:1] cannot resolve symbol
symbol : class Scanner
location: class INTERNAL_ASSESSMENT.Internal_Assessment_18_10 private Scanner x; ^
TheOnePrism 4 months ago
IS IT POSSIBLE TO USE ANOTHER METHOD BESIDES "RECORD ", OR WOULD IT EVEN BE NECESSARY.
90cdowns 4 months ago
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at H81_reading_from_file.readfile.readFile(readfile.java:27) at H81_reading_from_file.apples.main(apples.java:9)
Jesteria78 5 months ago
A few videos ago there was 30000+ views. Now there are 50000+ views. bunch of lazy people r trying to get to the good parts only!
the314Qwerty 5 months ago
Sorry, The Program Could Not Find The File Specified.
Exception in thread "main" java.lang.NullPointerException at readfile.readFile(readfile.java:16) at launcher.main(launcher.java:6) ?!?!?!?!?!?!?!?!??!!?!?!?!?!?!?!?!?!?! I copied this exactly -.-
Allenmarxchannel 5 months ago
@Allenmarxchannel couldn't find the file trying to read
TheRegimeister 5 months ago
"*cough* ah, whooping cough. Lol, I love your randomness in all of these! Thanks a bunch for all these videos, they're really helpful!
tuhin94 5 months ago
thanks!
Tusharchutani 6 months ago
Almost there :D
autom4 6 months ago
great tutorial as expected. wondering if you're covering vectors also... but i think its all GUI from here
ojstrike 7 months ago 6
Another way to get file contents:
while (x.hasNextLine()) System.out.println(x.nextLine());
nWANTED 7 months ago 20
@nWANTED yes this is far better compared to hasNext() because you read the whole line it is not confusing is it like wen u print the whole line, println but i think hasNext() is good to cover first in tutorial. java must be having many methods to read a file i guess.
ShwariDeveloper 2 months ago
I wonder if he'll ever cover why it always says that the default package is discouraged. Lets use a different package, bucky.
seed419 7 months ago in playlist Bucky's Java Tutorial
So x.hasNext() looks for the next line and x.next looks for the next word, right? Seems obvious based on the result but he never made that clear.
prebek 7 months ago
@prebek i think hasnext looks to see if there is another word not line... Im not sure though
mattrocks182 7 months ago
@mattrocks182 oh ok, i think you're right, thanks
prebek 7 months ago
it think we should put the try catch in the main too. When i trigger the error in the readfile class, it catch it but then the open read and close from the main class display errors too.
solde99 7 months ago
I have a small question. If the hasNext() method in the while returns only if there is still at least one token to read, but you use 3 tokens in a row on your code without rechecking with hasNext(), wouldn't it cause problems?
5ty1 7 months ago
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa fuck 81 tutorials in a row and that bastard is making more
latvianMCG 7 months ago
a, b, c, d, f, g?
Lol, i made it to the 81st tutorial...hard work ya know...
FreePKMNWalkthroughs 7 months ago
@FreePKMNWalkthroughs a, b, c, d, e, f >_< lol
FreePKMNWalkthroughs 7 months ago
@puimiu Shut up.
kevkeane94 8 months ago
YOU SHOULD START A SCHOOL!!!
imtihanahmed 8 months ago
@imtihanahmed seconded ^
ConZatheGolem 8 months ago
my teacher never teaches. it is from u that i have learned arrays and arraylists, and files. THANK YOU.
imtihanahmed 8 months ago
You talk so Good damn fast for a video tutorial, learn to speak more clearly and rarely. You could have made the tutorial a little longer then 7:51.
puimiu 8 months ago
Excellent tutorial dude, keep up the good work!
DeathKnight527 9 months ago
if you wanted to keep the values for a,b, and c so that you keep everything read from the file, you'ld use arrays a[] b[] c[] (with appropriate sizes) and iterate through each element in the arrays. You could then do a search a name or number or whatever you want to do with the data.
finnvoid 9 months ago
How would you read in from a csv file?
Natscol 9 months ago
thanks dude! :) owe you one, keep us posted!
auradistorter1 10 months ago
can someone pllzzzz tell me how can i handle the context of a file? for example lets say taht i want to find someone whith his last name and print his age . :( plzzz
Vlaxiti 10 months ago
String a = x.next();
in place of that can i use like:
int a = x.nextInt(); ???
will this work??
jock0man 10 months ago
THANK YOU
plutgamer 11 months ago
Hey bucky i was just wondering how does the method x.next() know to assign each part of the record first to a, then b, and then to c. I just thought if you're assigning x.next() to all three a, b , and c wouldn't all of them be the same?
sebg18 11 months ago
@sebg18 I believe it's because the spaces separates them. It reads the text and goes on to the "next()" part of the document with text in it. (Might wanna look that up to confirm it, but from what I've tested, that's true.)
Hope that helps!
zldamstr 9 months ago
How can I get my Java program, built in eclipse to ask for a command line argument before running or to just run in the cmd?
AMBentIn 11 months ago
thanks a lot!
I loved it!
mrdevi 11 months ago
hey bucky how comes you didn't teach us about fileinputstream and bufferedinputstream and datainputstream!?
usynn 11 months ago
your the best dude!
fxyrific 11 months ago
Bucky, where should i save the file? I tried the src and the bin folders of my project folders, but the system still can't find the file
360boxes 1 year ago
This has been flagged as spam show
Trusted name on Latino women marriage service rockmycity.info
dhfhfchcfh 1 year ago
do you have any tutorials on how to search for a word in a file???
ie if you have:
20 bucky roberts
60 joe doe etc in a file and we want to find bucky
how do we do that?
ubasta 1 year ago
i am stick with these tuts from the begging and have 6 more to watch as well
l69lspunkyl69l 1 year ago
how can you create two file and move the data from one file to another like to tranfer all the data from chinese.txt to another file that you created
stargem16 1 year ago
@stargem16 make a new file using formater(tutorial 79 if i remeber right) ... read the data from the first file (this one)... write them in the second(tutorial 80) wish that helped
Meneltour27 11 months ago
thank you!The Scanner-method is very useful!
Keep it up!
idiosynkrass 1 year ago
this really helps in my assignment..
eamedrolf 1 year ago
This has been flagged as spam show
Great! It really works! ;)
matkoklaic 1 year ago
hi,
how can I save the position(x,y) of a movable thing (=>x and y change) to a file.
I ask, because I am creating a game and i want to save the position of the charakter and load it later again.
THX
MurayTheBanana 1 year ago
@MurayTheBanana check his 80th tutorial on how to write to files and his 75th / 76th (I think) tutorials on how to register x and y positions with the mouse. 1 + 1 = 2:p
Just store those positions in the text file and you're done ;) load em whenever you like
lollylylols 1 year ago
What if you wanted to take those strings and store whole file into an arraylist? how would you go about doing that?
triggahapy 1 year ago
Great vid and why did u name the the things in chinese.txt this –––>
20 bucky roberts
60 joe doe
50 mike ike
49 sis priss
hilarious! anyway, great tut.
themacguy1001 1 year ago
fantastic tutorials :D
when you make a public sessions? or if you make where?
im from Portugal, if possible make here :D
thanks for all
Mac1355 1 year ago
how do you read 1line of a hole txt file with scanner
CleanGhettoKids101 1 year ago
what does printf do? compared to print and println
LearnTechTv 1 year ago
@LearnTechTv it just prints out a string differently. some people think its more organized idk
wwerichie 1 year ago
Great tutorial but I have one question...
How do I tell Java to skip a line each time I use the .format() method to write to the file???
abovestand 1 year ago
@ bucky , if u read this there's in issue about this tutorial , a couple of us have been havin , its posted in ur java forum , can u please check it out .
thanks
SInnerMario 1 year ago
@SInnerMario Did he help u with the solution to this problem?
aksultra 1 year ago
thanks
minhthuan0032000 1 year ago
Where did you save the .txt file?
FrimmiSigurds 1 year ago
@FrimmiSigurds wherever you want...
abovestand 1 year ago
thank's man !!
nadalomar01 1 year ago
Thank you so much Bucky! I really appreciate these Tutorials. You've helped me out with my programming class and its rly coming in handy this last part of the year. Thank you so much i really appreciate it ! :D
~Marc
chaomwb 1 year ago
100% more helpful than my university lab sessions. Thank you man! :)
jammish32 1 year ago
Excellent tutorial compared to paid online tutorials
and I have one question if u down load a mysql non-installer zip file how we can install it and how we can start the server service
TheApasya 1 year ago
thx for heping people and me You ar great guy..
Greetings from Poland
kloszi 1 year ago
How do you add another Record ?
theend1245 1 year ago
if i give like System.out.println(a);
it is printing the whole line can i know why
vbrshi 2 years ago
You are the best! Awsome!!
olivnt 2 years ago 6
Thanx Bucky for everything. awesome tutorials. I have a doubt. what if we want to read suppose all XML files. does "*.xml" does work ???? Thanx in advance.
srikanthtmt 2 years ago
@srikanthtmt Why not try it?
chubbystudios 2 years ago
Bucky I think you are the best. Coming straight out of Jamaica.
Teethousable 2 years ago
you are nuber one mr thenewboston
Thank-you so much ,y are nice...
You can show we the : JDBC ,web ,please !
Thank-you
LaBichTuyen 2 years ago
ya jdbc and web would be helpful.
nastyboy2099 2 years ago
ps. is there a tutorial for importing and interacting with home drawn images ie user designed GUI's?
messruth 2 years ago
Top Quality tutorials, please keep doing them
messruth 2 years ago 53
dude, i'm the kind of person, that uderstand way more if someone explain me, than reading the example, thnx, you are a great help, i need something like this for my project.
FPR 2 years ago
bucky your the man keeeeeep makin those tuts
phait08 2 years ago
still confused as a mofo
therooster83091 2 years ago
wow how come your java tutorials are a lot more than c++?
rax7 2 years ago
win
gammarush 2 years ago 3
great tuts bucky
keep em comin ;p
ShirokaneWashi 2 years ago
bucky, why dont you use a BufferedReader?(if u did i didnt watch whole vid)
eliteveteran 2 years ago
Scanner and BufferedReader are almost the same, it doesn't matter wich he uses..
MrKiller00224 2 years ago
awesome!
please keep them coming..
Can You make some videos about applets?
68kaspar 2 years ago
nyyyyyycccc
Hukam1 2 years ago
thank ya
Waranle 2 years ago
ttt
Waranle 2 years ago
cool :) i dont use java but ur very cool with these tuts :) 4 me the comp tut was cool :D
sakagjiata 2 years ago
Thanks Bucky!!!
bussysam2 2 years ago
nice
916myspacefreak 2 years ago
I love your tutorials! Keep them coming.
y0urfaceishide0us2 2 years ago
AAAH! UUUH !!
silver2screen 2 years ago