Re: Importar archivo csv usando struts

"Moises Alberto Lindo Gutarra" <[email protected]>
Newsgroups gmane.comp.java.javaspain
Message-ID <[email protected]>
un archivo csv es un archivo texto con un delimitador ","
cada fila es un registro, lo que tienes que hacer
es leer el archivo texto, algo asi:

import java.io.*;
import java.util.*;

public class FileIO
{
    public static void main(String[] args)
    {
        ArrayList bob = loadFile(args[0]);
        for (int i=0; i<bob.size(); i++)
            System.out.println(i+1 + ":\t" + bob.get(i));
    }

    public static ArrayList loadFile(String fileName)
    {
        if ((fileName == null) || (fileName == ""))
            throw new IllegalArgumentException();

        String line;
        ArrayList file = new ArrayList();

        try
        {
            BufferedReader in = new BufferedReader(new FileReader(fileName));

            if (!in.ready())
                throw new IOException();

            while ((line = in.readLine()) != null)
                file.add(line);

            in.close();
        }
        catch (IOException e)
        {
            System.out.println(e);
            return null;
        }

        return file;
    }
}

El día 10 de septiembre de 2008 10:14, estaisaderezados
<[email protected]> escribió:
> Hola,
>
> Estoy desarrollando una aplicación web con Struts y quiero saber como
> importar archivos .csv que nunca lo he hecho, la idea es importar un
> archivo csv con una lista de usuarios que a continuación seran
> grabados en una tabla en base de datos y de esta manera evitar tener
> que ir metiendo uno a uno los usuarios.
>
> Si me pueden ayudar los agradeceria, o si supieran de alguna dirección
> que expliquen como hacerlo.
>
> Gracias,
>
> 



-- 
Atentamente,
Moisés Alberto Lindo Gutarra
Asesor - Desarrollador Java / Open Source
Linux Registered User #431131 - http://counter.li.org/
Cel: (511) 995081720
MSN: mlindo-s5p+nkbmrd8Aspv4Qr0y0gC/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.