vrael Posted June 4, 2012 at 04:38 PM Report Share #460353 Posted June 4, 2012 at 04:38 PM Boa tarde, Tenho o seguinte código para ler ficheiros. public ArrayList<String> lerFicheiro() { String linhaActual = ""; BufferedReader infile = null; ArrayList<String> lines = new ArrayList<String>(); ArrayList<String> Campos = new ArrayList<String>(); int i=0; try { infile = new BufferedReader(new FileReader(this.NomeFicheiro)); do{ linhaActual = infile.readLine(); if(linhaActual!=null) { lines.add(linhaActual); ++i; } } while(linhaActual!=null); } Agora gostava de dividir cada linha sempre que encontra-se um espaço e guardar os dados(números) em vectores. Será que alguém me pode passar um tutorial ou dizer como se faz? Extremamente agradecido. Obrigado, VRael Link to comment Share on other sites More sharing options...
Rui Carlos Posted June 4, 2012 at 04:53 PM Report Share #460356 Posted June 4, 2012 at 04:53 PM Podes usar a função split: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String) Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
vrael Posted June 4, 2012 at 08:31 PM Author Report Share #460381 Posted June 4, 2012 at 08:31 PM Já criei o método da função split. Mas estou a ter dificuldades em guardar o conteudo. Porque o esquema é assim... X Y Z X Y Z E eu queria guardar a primeira palavra de cada linha na variavel X, a segunda na variavel Y e a terceira na variavel Z. Link to comment Share on other sites More sharing options...
Rui Carlos Posted June 4, 2012 at 09:09 PM Report Share #460390 Posted June 4, 2012 at 09:09 PM O resultado é colocado num array. Depois podes atribuir às variáveis x, y e z os valores do array. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now