Thank you so much for making a tutorial that actually tells us what each thing does and giving us tips instead of "do dat ting because dats wat make it work!"
if you have a space or two in your line say : "this is a line" then `.next()` method will only go as far as the first space. to get the whole line, you should use `.nextLine()`
Fix it at source. If many instances, manipulate the source prior to import first in the .csv with space delimiters and concatenates. If the space is telling as some sort of convention, change it to a dash..ie - after delimiting by space in "text to columns" in excel. =concatenate(cell containing MYMY,"-",cell containing ZZZ). The result in the adjacent column would be MYMY-ZZZ, leaving you with a solid string and eliminating the lost data. Copy/Paste Values over the original data for MYMY ZZZ.
hey.can you tell how to store the above data in format like : x1= line1, x2 = line2 , x3= line3 ..... where line1,line 2.. are the lines of data in csv file
Member variables are accessible anywhere in the Class. So, to access 'values' anywhere in the class simply move its declaration (String[] values;) to the class body, that is, move it outside the main() function.
+GOURAB DASGUPTA you got to get to the particular line using a loop and then once you get to the particular line us get() function to grab a certen part of the line. for ex: get(i+5) to get the 6 value in the line
just use a counter. Declare an integer called "counter" before the loop and set it to 1 (or 0) and increment it inside the loop "counter++". Then all you need is to say: if (counter == your number) // perform the logic
Hello Sir, Hope you are doing very well, My Question: How to compare two same CSV files in Java, And if any mismatch found then print those values. Please help me in this problem. Thanks Rishu(India)
How comes every video I watch dont create the file, I'm going crazy here trying to figure that out, they drag and drop the file, if you're a beginner and you have a test you need to know how to create it but no one does this step I'm giving its simply but I wouldn't know, no one create it they just drag and drop smh.
Thanks this was helpful. But i had a challenge, after using inputStream.next to get a line and after i have split the line with (",") i discovered the last value in a line is not being picked because it contained a space. How can i get over this. Below is the data line affected JJJ,29-11-12,JHU,936,MYMY*** which was supposed to be JJJ,29-11-12,JHU,936,MYMY ZZZ*** anyone pls assist
String fileName = "csv/engine.csv"; public Main() { try { Scanner sc = new Scanner(file); while(sc.hasNext()) { String data = sc.next(); String[] values = data.split(","); float x = Float.parseFloat(values[0]); float y = Float.parseFloat(values[1]); float z = Float.parseFloat(values[2] } sc.close(); }catch(Exception e) { e.printStackTrace(); } I get exception java.lang.ArrayIndexOutOfBoundsException how to slove this exception
for all the video I have been watching, it's hard to believe the one from 9 years ago is the most useful one...thanks
I searched for the best tutorial for this. And without a doubt I can say that this 9 year old video explained it the best.
Thanks Sir ❤️
Man, your are really good!!!
By far the best video on IO Java I have seen on youtube.
Keep on educating us dude, you got a talent!!!
Thank you so much for making a tutorial that actually tells us what each thing does and giving us tips instead of "do dat ting because dats wat make it work!"
Señor Vidal, you're a legend
if you have a space or two in your line say : "this is a line" then `.next()` method will only go as far as the first space. to get the whole line, you should use `.nextLine()`
Great comment!
Thank you sir..
Thanks man easy fix
Yep, I did the same
thank you!
This video saved me, thank you very much!
Thank you so much !!!!!!!!!!!! It really helped me a lot with my homework!!!
impressive, very detailed,subscribed, thanks a lot for creating such awesome video. Hopefully I can watching all your video in 3 weeks. -,-
Thank you so much needed this
Fix it at source. If many instances, manipulate the source prior to import first in the .csv with space delimiters and concatenates. If the space is telling as some sort of convention, change it to a dash..ie - after delimiting by space in "text to columns" in excel. =concatenate(cell containing MYMY,"-",cell containing ZZZ). The result in the adjacent column would be MYMY-ZZZ, leaving you with a solid string and eliminating the lost data. Copy/Paste Values over the original data for MYMY ZZZ.
awesome tutorial! keep up the good work!
Just want to say a big thank you
hey.can you tell how to store the above data in format like : x1= line1, x2 = line2 , x3= line3 ..... where line1,line 2.. are the lines of data in csv file
How would you find the largest number in the file for one specific set of values?
thank you so much Mr. Vidal!
how do you fetch the data using a column header name? Here you have used column number. Is it possible to use column name? If yes, please tell how.
what if the value is empty then execution fails ??
Thank you very much! this was so helpful :D
great tutorial, how would you read in a csv file and put it into a linked list and then sort it by an insertion sort by name i would say
how would I read one line of the csv file lines
How do you get it to find the shortened path name. I had to use "c:\\User\\...data.csv" Sorry if this is a simple question.
is there anyway to convert this CSV file into JSON format ?
You sound swedish !
Nice video
Thanks a lot, it was really helpful
what if we have to read the data row by row?
use .nextLine() method instead of .next()
Is there a way to automate the downloading of a csv file in java so that you could update the daily price of a stock in a hassle free way for a user?
+trey collins Instead of doing that you could also set the file location to a website and use a package/library that would allow you to do that.
+trey collins Use Selenium to automate the download and then use java for comparison and update.
helped me, Thankyou.. :)
Can you upload the code as well? it would help us to understand it better
Very helpful, thank you!
I appreciate your help :)
Can i ask one question..?
I want to use "values" variable outside while() loops, then how can i fix this codes..?
Member variables are accessible anywhere in the Class. So, to access 'values' anywhere in the class simply move its declaration (String[] values;) to the class body, that is, move it outside the main() function.
oh,,,I understood at all! Thank you for your kind reply!!!!!
Sir can you please share the data file so I can try this out with the values on my own
Hello, i am new here, what can i do if i would like to see CSV in a jtable, I can see.. you use eclipse, is it different than netbeans?
i get this error The system cannot find the file specified
same, I even have the import java.io.File; correctly, hm
what is an input stream
Using the above code i m nt gettin d whole line as my output,what shall i do??
Itishree Mandal.nextLine() instead of.next()
How can I calculate 20 days moving average from this code?
How come you don't have to put down the entire path to the file?
How to fetch a particular row?
Thanks bro, you saved my ass
can you make a new tutorial where you show how to save data and read data from a log file in android development ( also java ) it would help me a lot
5:30 Any body else getting just "data.csv" as a result?
bro, how to start reading data from a particular line number in a csv file ??
+GOURAB DASGUPTA you got to get to the particular line using a loop and then once you get to the particular line us get() function to grab a certen part of the line. for ex: get(i+5) to get the 6 value in the line
just use a counter. Declare an integer called "counter" before the loop and set it to 1 (or 0) and increment it inside the loop "counter++". Then all you need is to say:
if (counter == your number)
// perform the logic
thanks,very good.
Hello Sir,
Hope you are doing very well,
My Question: How to compare two same CSV files in Java, And if any mismatch found then print those values. Please help me in this problem.
Thanks
Rishu(India)
what IDE is this? IntelliJidea?
looks like eclipse...
Thank you sir
Thank you
salut comment importer des données d'un fichier excel vers une base de données en java et netbeans ou eclipse?
what ide is this?
How comes every video I watch dont create the file, I'm going crazy here trying to figure that out, they drag and drop the file, if you're a beginner and you have a test you need to know how to create it but no one does this step I'm giving its simply but I wouldn't know, no one create it they just drag and drop smh.
Thanks this was helpful. But i had a challenge, after using inputStream.next to get a line and after i have split the line with (",") i discovered the last value in a line is not being picked because it contained a space. How can i get over this. Below is the data line affected
JJJ,29-11-12,JHU,936,MYMY***
which was supposed to be
JJJ,29-11-12,JHU,936,MYMY ZZZ***
anyone pls assist
Thanks!!!
Thankyou... :)
the split(",") is adding blocks of spaces to my array, how do i ignore the spaces?
+ISAACTheBro .trim() if they are on the outside .replace(" ","") if they are on the inside.
java.lang.ArrayIndexOutOfBoundsException: 2 shows how i solve this please help...
check your csv file if it has space in any line use inputStream.nextLine() instead of inputStream.next()
@@boo4330 thank you
String fileName = "csv/engine.csv";
public Main() {
try {
Scanner sc = new Scanner(file);
while(sc.hasNext()) {
String data = sc.next();
String[] values = data.split(",");
float x = Float.parseFloat(values[0]);
float y = Float.parseFloat(values[1]);
float z = Float.parseFloat(values[2]
}
sc.close();
}catch(Exception e) {
e.printStackTrace();
}
I get exception
java.lang.ArrayIndexOutOfBoundsException
how to slove this exception
If you use powershell,you can do the same thing just use 'import-csv "\\Path\data.csv" | where-object{$_.High -gt 642 }',so fast so simple
If only a few easily spotted instances, I'd overwrite manually.
.next() method will place the pointer to the next word only. You must use .nextLine() method to traverse line by line.
it is not working showing error
Simple, change your delimiter to (" ,") ... just add a space
no audio?