Ver Mensaje Individual
  #4 (permalink)  
Antiguo 14/12/2014, 21:00
DarkMaster_21
 
Fecha de Ingreso: diciembre-2014
Mensajes: 4
Antigüedad: 9 años, 4 meses
Puntos: 0
Respuesta: Leer un txt en un jlist

Con este código básicamente lees el archivo y retorna un String[] con los datos del archivo. Partí de la base de que tu archivo está así:
Mario
Maria
Carlos
Rodolfo

Cualquier cosa que no entendás, pregunta.

Código Java:
Ver original
  1. private String[] lista() {
  2.  
  3.         ArrayList<String> listtxt = new ArrayList<String>();
  4.  
  5.         try {
  6.             FileInputStream fis = new FileInputStream(new File("file.txt"));
  7.             InputStreamReader isr = new InputStreamReader(fis, "UTF8");
  8.             BufferedReader br = new BufferedReader(isr);
  9.  
  10.             String line = br.readLine();
  11.  
  12.             while (line != null) {
  13.                 listtxt.add(line);
  14.                 line = br.readLine();
  15.             }
  16.  
  17.             br.close();
  18.         }
  19.         catch (IOException ioe) {
  20.         }
  21.  
  22.         String[] array = new String[listtxt.size()];
  23.         array = listtxt.toArray(array);
  24.  
  25.         return array;
  26.     }