Okay guys first and foremost let me say that I am a NOVICE when it comes to programming in JAVA. I am teaching myself, so with that said please bear with me as I am doing the best I can with what I have. With that said, here is my dilemma!!!
I have a file "Users.csv" that stores username and password fields.
username,password
josh,123456ABC
bman,turtlestew123
etc...
What I am trying to do is...
- Read the lines from this document (Users.csv) (which is in the same directory as the class file)
- Split the lines using .split(","); on the input
- Store split 1 in an array[0] and split 2 in the same array[1]
The array must be able to grow as I add users to the file. Eventually I will want to verify information from the array but my main concern right now is how to even get the information into the array. Here is what I am playing around with, but I don't know how to make it do what I want...
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class BufferedReaderExample {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new FileReader("Users.csv")))
{
String sCurrentLine;
String first = "Username is: ";
String second = "Password is: ";
while ((sCurrentLine = br.readLine()) != null) {
String[] information = sCurrentLine.split(",");
String username = information[0];
String password = information[1];
System.out.println(username);
System.out.println(password);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
This code will read the lines, and will split them and output them to the screen... but it isn't storing them in the array, so I cant use the array to look for specific elements.
This is for a login gui. simple username and password fields. When the person hits the logon button, I want it to pull the information from the file, check the username and then verify their password. Again this part is the big picture but just wanting to let you know what it is being used for.
Also, please remember that I am very inexperienced and if you post code please don't use something similar but different as that just confuses me even more.