java读写CSV文件

2020-12-13 03:53

阅读:516

标签:val   value   token   相互   文件中   读取   pat   ready   学习   

java读写CSV文件

觉得有用的话,欢迎一起讨论相互学习~Follow Me

参考文献
读取csv文件中数据
将数据保存为csv文件格式

读取CSV文件中的数据

import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class readCSV {
    void readCSV(String readpath, ArrayList Nolist, ArrayList Dnalist) {
        File inFile = new File(readpath);
        try {
            BufferedReader reader = new BufferedReader(new FileReader(inFile));
            while (reader.ready()) {
                String line = reader.readLine();
                StringTokenizer st = new StringTokenizer(line, ",");
                int NO;
                String DNAsequence;

                if (st.hasMoreTokens()) {
                    NO = Integer.valueOf(st.nextToken().trim());
                    DNAsequence = String.valueOf(st.nextToken().trim());
                    Nolist.add(NO);
                    Dnalist.add(DNAsequence);
                }
            }
            reader.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}

将数据保存为csv格式

package Readcsv_testV0;


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

public class OutputCSV {
    public static void writeCSV(ArrayList DNA, ArrayList Con, ArrayList Hp, ArrayList Hm, ArrayList Si, ArrayList Tm, ArrayList GC, String path) {
        try {
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
            for (int i = 0; i 

java读写CSV文件

标签:val   value   token   相互   文件中   读取   pat   ready   学习   

原文地址:https://www.cnblogs.com/cloud-ken/p/11093594.html


评论


亲,登录后才可以留言!