scanner = new Scanner(new FileReader("caminho"))
.useDelimiter(",|\n");
while (scanner.hasNext()) {
String nome = scanner.next();
String rg = scanner.next();
String cpf = scanner.next();
scanner = new Scanner(new FileReader("caminho"))
.useDelimiter(",|\n");
while (scanner.hasNext()) {
String nome = scanner.next();
String rg = scanner.next();
String cpf = scanner.next();
A nice way is to use FileWriter methods to create / edit the file and FileReader to read.
public void gravar() {
FileWriter fileWriter;
BufferedWriter bufferedWriter;
try {
fileWriter = new FileWriter("configuracoes\config.txt");
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write("localhost");
bufferedWriter.close();
fileWriter.close();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Ocorreu um erro:\n" + ex.getMessage());
}
}
public final void lerArquivo() {
try {
FileReader fileReader = new FileReader("configuracoes\config.txt");
BufferedReader br = new BufferedReader(fileReader);
try {
setIP(br.readLine());
br.close();
setUrlPorIP(getIP());
} catch (IOException ex) {
BancoDeDados.database.tratamentoDeErro(ex, "");
}
} catch (FileNotFoundException ex) {
new File("configuracoes").mkdir();
File f = new File("configuracoes\config.txt");
try {
f.createNewFile();
gravarLinhaDeIP();
lerArquivoConfig();
} catch (IOException ex1) {
//JOptionPane.showMessageDialog(null, "O arquivo 'config.txt' não existe.\n"
// + "Foi tentado cria-lo mas algo saiu errado.\n"
// + "Tente criar o arquivo Manualmente");
}
}
}
Official Documentation: