Assigning variables to columns in a file

When displaying the contents of the credential file, I'm trying to apply each column of data to a variable. For example:

a = griffen.keyes

b = 108....

c = alphabet soup

d = zookeeper

The "c " variable it's not working correctly. Java is seeing this as two values despite the "".

How do I fix that?

Attached is a screenshot that I am reading from.
Below is my code so far.

package openCredFile;
import java.util.*;

public class TestingRandomMethods {
   public static void main(String[] args)throws IOException{
       TestingRandomMethods T = new TestingRandomMethods();  
       T.readFile(); //The main method calls these methods and executes them. It's the readFile method that prints the info.
    Scanner CredData; //Putting this outside of the method makes it available to all methods?
    public  void openFile() throws IOException {    //I had an error until I added "throws IOException" when trying to open the file.
        CredData = new Scanner(new File("credentials.txt")); //Opens the file.
        catch(Exception e){
            System.out.println("Could not find file.");
    public void readFile(){
        while(CredData.hasNext()){ //will loop until it reaches the end of the file. hasNext means to read the entire file.
            String a =;
            String b =;
            String c =;
            String d =;
            //String e =;
            //String f =;
            //System.out.printf("%s %s %s %s \n", a,b,c,d); //I put in the format and the variables that I want to print.
    public void closeFile(){
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

System.out.printf("%s %s %s %s \n", a,b,c,d); 

Open in new window

The only lines in that file with four tokens are the last two. The rest have five
isamesAuthor Commented:
I don't understand what you are talking about. I am just starting to learn Java. Can you elaborate for me?
isamesAuthor Commented:
Ok. I get what you are saying, that's why I posed the question.

How do I make the compiler read "alphabet soup" in the doc as one token?
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

You're lucky, it's tab-separated, so  try

CredData = new Scanner(new File("credentials.txt")); //Opens the file.
CredData.useDelimiter("\t+|[\r\n]+"); // delimiters are tabs and linefeeds

Open in new window

btw, that should be credData as Java variable names begin lower case

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>> credData as Java variable names begin lower case

Since you are just learning Java, I'd like to clarify that this is not a language rule but just a convention so that when code is passed from one developer to another, they will be able to pick up the code organization a little faster. Here is a link that gives more of the Code conventions.
isamesAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.