Reading and parsing delimited CSV data from a file into an Object in Java

  Рет қаралды 52,245

Brandan Jones

Brandan Jones

8 жыл бұрын

Access a file with java.io.File; read the data with java.util.Scanner and nextline(). Use the split() method to parse the file contents by a delimiter. Take the parsed contents, and insert them into an object.
This video is part of a playlist, available here: • Computer Programming 1...
The source code for this video is available on GitHub at github.com/discospiff/US16Veh...

Пікірлер: 43
@Gamuss12345
@Gamuss12345 6 ай бұрын
OMG your way of teaching is soooooo much better than all of the KZbinrs I've seen before! Incredible! Very very beginner-friendly! Thank you! :)
@discospiff
@discospiff 6 ай бұрын
Thanks, I really appreciated your endorsement! IT skills will serve you well. Keep me updated on your journey!
@bananaapple2253
@bananaapple2253 10 ай бұрын
Since today is 30/9/2023 but the video is so usefull for me just becuase it actually help me to figure out how to done my assignment. Thank you so much for the effort
@discospiff
@discospiff 9 ай бұрын
That's funny! This is an ooooooooold video. :)
@AhmedHadiPADI_scuba_instructor
@AhmedHadiPADI_scuba_instructor 7 жыл бұрын
very very professional explanation! going slowly and clear voice. love it.
@discospiff
@discospiff 7 жыл бұрын
Excellent! Thanks for the feedback.
@AhmedHadiPADI_scuba_instructor
@AhmedHadiPADI_scuba_instructor 7 жыл бұрын
you welcome! what would you do if you had multiple lines of numbers? thanks!
@michaelhutchinson213
@michaelhutchinson213 6 жыл бұрын
My first time commenting on a video, but really wanted to say thank-you, very well explained, great help
@discospiff
@discospiff 6 жыл бұрын
Excellent, thanks for the feedback! I'm glad I made your first time comment. :)
@gabriel9668
@gabriel9668 5 жыл бұрын
Thank you very much! I am working on this assignment for my class and this video helped a lot! :)
@williaminfiesto2529
@williaminfiesto2529 3 жыл бұрын
This was very helpful and easy to understand. Thank you!
@discospiff
@discospiff 3 жыл бұрын
Thanks for the feedback! I strive to make my videos easy for a wide audience to understand, so I appreciate hearing when I've met my goal.
@58gullu58
@58gullu58 4 жыл бұрын
What if you have multiple lines and want to create an object for each line and add them in an Array?
@fannymoryta
@fannymoryta 7 жыл бұрын
Great tutorial.!
@discospiff
@discospiff 7 жыл бұрын
:) Thanks.
@caseycruz7959
@caseycruz7959 2 жыл бұрын
Great Video! Would you be able to do this with one of the aariables as String[ ] rather then just a string?
@lauragriffiths3332
@lauragriffiths3332 3 жыл бұрын
all i can say is THANK YOU !!!
@discospiff
@discospiff 3 жыл бұрын
You're welcome! I'm glad it helped.
@SB-ou5yp
@SB-ou5yp 5 жыл бұрын
Hi Brandon, your tutorial was very useful but I've been having issues with a CSV file, particularly when printing out the cells in the last column of each row within my CSV file. It's like the last cell in the previous row is attached to the first cell in the next row of the file. The cell contents print in the correct position but they print simultaneously as if they are joined together. For instance, let's say I have a CSV file with the contents: 7,7,7,7 3,3,3,3 When printing each number, the first three sevens in the first row print individually but the last seven prints with the first three in the next row, like so: 1st pass 7, 2nd pass 7,7, 3rd pass 7,7,7, 4th pass 7,7,7,7 3, My program aims to store each element individually and cannot do so until I figure out how to separate the last and first lines. Do you have any idea on how to solve this?
@mabblers
@mabblers 6 жыл бұрын
Very good video. Do you have one like with more rows from the file?
@discospiff
@discospiff 6 жыл бұрын
Hmmmm. I would just put the Scanner's read method in a loop, and iterate over the file until complete.
@jonathanharris2326
@jonathanharris2326 3 жыл бұрын
This was incredibly helpful for my first project in java. I'm used to C++ but i'm starting to really like java, so easy!
@discospiff
@discospiff 3 жыл бұрын
Glad to hear that! This is an older video in my library; I'm happy to hear it's still useful. :)
@safarnama04
@safarnama04 6 жыл бұрын
my program is not returning correct output for next lines, it is working for first line only
@lennysmileyface
@lennysmileyface 5 жыл бұрын
I do this instead. Have your file in myproject/eg/ new FileReader("eg/" + fileName + ".fileextension")
@frankkid010
@frankkid010 5 жыл бұрын
What if the file had multiple vehicles, let's say 5, is there a way to do this without manually creating 5 variables for the vehicles?
@discospiff
@discospiff 5 жыл бұрын
Use an array... ArrayList I believe I covered that in a later video.
@frankkid010
@frankkid010 5 жыл бұрын
@@discospiff thank you
@HazzM
@HazzM 4 жыл бұрын
Any link or title to find this? I've looked but nothing jumped out at me
@marcusdouglas332
@marcusdouglas332 7 жыл бұрын
Lets say that one cars you made had more than one mpg value, how could you represent that on the same line?
@discospiff
@discospiff 7 жыл бұрын
If it's a one to many relationship, I would split the "many" side into a separate file that is foreign-keyed back to the main cars file, using a unique identifier. Alternatively, you could do it all in one file if you have an additional field before the mpgs: a field that tells you how many MPGs follow. That way, you know how many mpgs to expect, and you read and parse each of them, then continue with the next field.
@marcusdouglas332
@marcusdouglas332 7 жыл бұрын
So there isn't a way to have a flexible field that could hold more than one value? Say we input the amount of cash transactions a business has in one day.
@copieselect9846
@copieselect9846 3 жыл бұрын
I used the same technique for student detail but do not know how to make that in loop and form a array of student objects
@discospiff
@discospiff 3 жыл бұрын
How can I help?
@XSource100
@XSource100 2 жыл бұрын
how do you read objects from csv and insert them into object class
@user-rl4dz2ur4w
@user-rl4dz2ur4w 8 ай бұрын
it works with .tsv files?
@asharshahab1982
@asharshahab1982 Жыл бұрын
What happens when i encounter a blank row while reading the excel.csv file? How do i skip that line whiout any run time error sir?
@discospiff
@discospiff Жыл бұрын
I'd check for the length of the row first, and decide whether or not to skip. Or... use a try-catch block to catch an error from an empty row, and then decide how to process it.
@NazmulIslam-zc9te
@NazmulIslam-zc9te 7 жыл бұрын
nice
@cithpo5938
@cithpo5938 7 жыл бұрын
Dear Mr. Brandon, can I get your codes for study?
@discospiff
@discospiff 7 жыл бұрын
Sure, it's freely available on GitHub here: github.com/discospiff/US16Vehicles
@cithpo5938
@cithpo5938 7 жыл бұрын
Thank you so much
@budpatterson8357
@budpatterson8357 7 жыл бұрын
First
Reading from a CSV File and Searching for a Record in Java
18:43
Max O'Didily
Рет қаралды 55 М.
Java: Read a CSV File into an Array #49
13:47
Alex Lee
Рет қаралды 199 М.
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 13 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:40
CRAZY GREAPA
Рет қаралды 29 МЛН
Edit a Record in a CSV/txt File Java
15:47
Max O'Didily
Рет қаралды 58 М.
Water powered timers hidden in public restrooms
13:12
Steve Mould
Рет қаралды 733 М.
Reading a CSV in Java
10:42
Cody Henrichsen
Рет қаралды 1,5 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 778 М.
Simple Example of JSON with GSON and JsonDeserializer
21:15
Brandan Jones
Рет қаралды 399
Parse JSON using Java
22:27
Coding Simplified
Рет қаралды 6 М.
Java Programming Tutorial - 81 - Reading from Files
7:51
thenewboston
Рет қаралды 714 М.
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 13 МЛН