So I am making a username password database to write it in a file:
import java.util.*;
import java.io.*;
import java.lang.*;
public class createfile {
private Formatter x;
public void openFile(){
try{
x = new Formatter("okey.fil");
}
catch(Exception e){
System.out.println("error get it right");
}
}
public void addRecords(){
Scanner input = new Scanner(System.in);
System.out.println("Enter number of records");
int num = input.nextInt();
for(int counter = 1; counter<=num; counter++){
String username = input.nextLine();
String email = input.nextLine();
String userpass = input.nextLine();
String emailpass = input.nextLine();
x.format("%s%s%s%s%s%s%s%s", username,"\t", email,"\t", userpass,"\t", emailpass, "\n");
}
}
public void closeFile(){
x.close();
}
}
public class Main {
public static void main(String[] args) {
createfile f = new createfile();
f.openFile();
f.addRecords();
f.closeFile();
}
}
Problem is, it outputs incorrect in wrong format: i'll use 2 for number of records (num = 2) and the strings will equal the same to what it is asking for (username = username, emailpass = emailpass...) and this is the output:
username email userpass
emailpass username2 email2 userpass2