Boa tarde, estou com o seguinte problema leio de um arquivo txt e cada linha eh lida com uma virgula como split porem quando ha algum espaço antes dessa virgula o programa da pau, vou mostrar o meu metodo que eu adiciono a linha e o que eu leio a lista de contatos no caso.
Um metodo que eu pego tudo que eu leio e separo para cada atributo.public static List<Contato> carregarDoArquivo() {
File ArqTxt = new File("C://lista.txt");
FileInputStream fi = null;
List<Contato> lista = new ArrayList<Contato>();
try {
fi = new FileInputStream(ArqTxt);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String readLine = "";
String conteudo = "";
Scanner scan = new Scanner(fi);
int cont=0;
while (scan.hasNext()) {
readLine = scan.next();
cont++;
String b[] = readLine.split(",");
Contato c = new Contato(b[0], b[1], b[2]);
lista.add(c);
o metodo que eu adiciono no txt
public void add(String nome,String email,String produto) throws IOException{
File Arqtxt = new File("C://lista.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(Arqtxt);
} catch (FileNotFoundException ex) {
Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
String readLine="";
String conteudo="";
Scanner scan = new Scanner(fis);
while (scan.hasNext()) {
readLine = scan.next();
conteudo += readLine +"\r\n";
}
conteudo += nome+","+email+","+produto;
FileOutputStream fo = null;
try {
fo = new FileOutputStream(Arqtxt, false);
} catch (FileNotFoundException ex) {
Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
try {
fo.write(conteudo.getBytes());
} catch (IOException ex) {
JOptionPane.showInputDialog(null,"Erro na hora de gravar");
Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
}
Gostaria de saber como ignoro um espaço