Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/06/2011, 22:12
ZedGe1505
 
Fecha de Ingreso: junio-2011
Mensajes: 289
Antigüedad: 13 años, 9 meses
Puntos: 15
Cargar txt A un arreglo

Bueno la idea es la siguiente:

Tengo un archivo .txt con el formato:

12345678
87654321
.
.
.
.

en donde cada numero tengo que pasarlo a una posición de un arreglo ej:

arreglo[0]=1
arreglo[1]=2
.......


espero entiendan tengo un código pero me lee los saltos de linea y me llena posiciones con espacios

Cita:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class Main {


public static void main(String[] args) throws IOException {
FileReader entrada=null;
StringBuilder str=new StringBuilder();
char[] datos = new char[24];
int n=0;

try{
BufferedReader fileIn = new BufferedReader(
new FileReader ("u.txt"));
int read = fileIn.read();

while (read != -1){
datos[n]=(char) read;

n++;
read = fileIn.read();

}
}
catch (FileNotFoundException ex)
{
}
catch (IOException ex)
{
}
}
}