Chris Burn
Chris Burn

Reputation: 11

New line when writing to a text file Java

i'm struggling with a Java class that i'm trying to implement. Have a look at the class below. Excuse any poor coding you spot, i've just started learning java.

 public void processFiles() 
    {

           output.print(name + " " + id + " ");


        while(input.hasNext())
        {
            String firstName = input.next();
            String lastName = input.next();
            String accNumber = input.next();
            int nextInt = input.nextInt();
            output.print(firstName);
            output.print(lastName);
            output.print(accNumber);
            output.print(nextInt);
            total = total + nextInt;
            count = count + 1;

        }
        output.print("There are " + count + " accounts which together hold" + total + " points.");
        closeLinks();
    }
}

When I open the file i've created the text is all on one line and I can't work out how to start a new line. I've tried inserting '\n' into the code without success. Can someone please help.

Upvotes: 0

Views: 95

Answers (2)

user6672223
user6672223

Reputation:

try to use output.println() or output.print(data+ "\n")

Upvotes: 1

dumbPotato21
dumbPotato21

Reputation: 5715

Replace all

output.print();

with

output.println();

This would result in printing each on a separate line

Upvotes: 1

Related Questions