java 读取csv文件代码

java 读取csv文件代码<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" errorpage="" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>java 读取csv文件代码</title>
</head>

<body>
<%
/*

*/

import java.io.bufferedreader;
import java.io.bufferedwriter;
import java.io.file;
import java.io.filereader;
import java.io.filewriter;
import java.io.ioexception;
import java.text.simpledateformat;
import java.util.arraylist;
import java.util.date;
import java.util.list;
import java.util.stringtokenizer;
import java.util.logging.filehandler;
import java.util.logging.formatter;
import java.util.logging.level;
import java.util.logging.logrecord;
import java.util.logging.logger;

public class inputfile
{
    private static logger getlogger()
    {
        try
        {
            filehandler hand = new filehandler( "c:/test/log.txt" );
            hand.setlevel( level.all );
            logger log = logger.getlogger( "log_file" );
            hand.setformatter( new myloghander() );
            log.addhandler( hand );
            return log;
        }
        catch( exception e )
        {
            e.printstacktrace();
        }
        return null;

    }

    public static list< list< string > > fileinput( file file )
    {
        list< list< string > > listoflist = new arraylist< list< string > >();
        try
        {
            if( file.exists() )
            {
                bufferedreader reader = new bufferedreader( new filereader( file ) );;
                string line;
                line = reader.readline();
                for( ; line != null; line = reader.readline() )
                {
                    stringtokenizer stokenizer = new stringtokenizer( line, " " );
                    list< string > list = new arraylist< string >();
                    while( stokenizer.hasmoreelements() )
                        list.add( stokenizer.nexttoken() );
                    listoflist.add( list );
                }
            }
            else
                getlogger().info( file + " not exist" );

        }
        catch( ioexception e )
        {
            getlogger().info( e.getmessage() );
        }

        return listoflist;
    }

    public static list< list< string > > changevalue( list< list< string > > input, list< list< string > > param )
    {
        for( list< string > list : param )
        {
            int row = integer.parseint( list.get( 0 ) );
            int line = integer.parseint( list.get( 1 ) );
            string value = list.get( 2 );
            input.get( row - 1 ).set( line - 1, value );
        }
        return input;
    }

    public static string fileoutput( list< list< string >> input )
    {
        string string = null;
        for( int i = 0; i < input.size(); i ++ )
        {
            list< string > list = input.get( i );
            for( int j = 0; j < list.size(); j ++ )
            {
                if( j == list.size() - 1 )
                    string += list.get( j ) + "n";
                else
                    string += list.get( j ) + " ";
            }
        }
        return string;
    }

    public static void writefile( string string, string pfad )
    {
        try
        {
            file datafile = new file( pfad );
            bufferedwriter writer = new bufferedwriter( new filewriter( datafile ) );
            writer.write( string );
            writer.close();
        }
        catch( ioexception e )
        {
            getlogger().info( e.getmessage() );
        }
        }

    public static void main( string[] args ) throws ioexception
    {

        file datefile = new file( args[0] );
        file parafile = new file( args[1] );
        list< list< string >> inputfile = inputfile.fileinput( datefile );
        list< list< string >> paramfile = inputfile.fileinput( parafile );
        inputfile = inputfile.changevalue( inputfile, paramfile );
        string string = inputfile.fileoutput( inputfile );
        inputfile.writefile( string, args[2] );
    }
}

class myloghander extends formatter
{
    public string format( logrecord record )
    {
        date date = new date();
        simpledateformat sdf = new simpledateformat( "yyyy/mm/dd hh:mm:ss" );
        return sdf.format( date ) + ":" + record.getmessage() + "n";
    }
}

%>
</body>
</html>

时间: 2024-10-25 18:00:20

java 读取csv文件代码的相关文章

php fgetcsv读取csv文件代码

php教程 fgetcsv读取csv文件代码 function get_csv_contents( $file_target ){ $handle  = fopen( $file_target, 'r'); while ($data = fgetcsv($handle, 1000, ",")) {             $num = count($data);         echo "<p> $num fields in line $row: <br&

根据不同的操作系统读取配置文件/java读取属性文件代码

package cn.com.css.common.util; /** * @brief OSEnum.java 操作系统的枚举 * @attention * @author 涂作权 * @date 2014年4月3日 * @note begin modify by null */public enum EOSPlatForm { Any("any"), Linux("Linux"), Mac_OS("Mac OS"), Mac_OS_X(&qu

java读取csv文件内容示例代码_java

复制代码 代码如下: package com.huateng.readcsv; import java.io.BufferedReader;import java.io.FileReader;import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class CsvUtil {        private String fileName = null;        private B

java读取csv文件和写csv示例分享_java

复制代码 代码如下: import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.

java读取word-excel-ppt文件代码_java

WORD: import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.poi.hwpf.extractor.WordExtractor; import java.io.File; import java.io.InputStream; import java.io.FileInputStream; import com.search.code.Ind

php fgetcsv读取csv文件代码(1/2)

 代码如下 复制代码 function get_csv_contents( $file_target ){     $handle  = fopen( $file_target, 'r');     while ($data = fgetcsv($handle, 1000, ",")) {             $num = count($data);         echo "<p> $num fields in line $row: <br>

java生成csv文件 自己定义表头、用sql查询内容,把内容和表头放到表里 , 最好有代码示例

问题描述 java生成csv文件 自己定义表头.用sql查询内容,把内容和表头放到表里 , 最好有代码示例 30C java生成csv文件 ,自己定义表头.用sql查询内容,把内容和表头放到表里 , 最好有代码示例 解决方案 csv文件最简单了,就是文本格式,逗号分割字段,换行分割记录.你自己sql循环,然后写文件,要表头的话,先输出一行作为表头就可以了. 解决方案二: 我要测试导出csv文件,response.getOutputStream()报空指针异常 解决方案三: 哪位大神有关于导出cs

java代码-关于poi类java读取Excel文件出现ioexception异常Invalid header signature

问题描述 关于poi类java读取Excel文件出现ioexception异常Invalid header signature 读取是因为头部文件无法识别,我按一般方法是另存为就可以了,有没别的方法是通过代码实现的,我写的功能是通过jsp来上传excel到临时文件,在用poi类来读取,所以打开excel另存为的方法不适合我,求救,很急 解决方案 用poi处理excel文件异常:java.io.IOException: Invalid header signature; read 23380427

java读取指定文件内容代码

java读取指定文件内容代码 <%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" errorpage="" %> <html xmlns="http://www.111cn.net/1999/xhtml"> <head> <meta http-equ