• 拷贝txt文本中的某行的数据到excel中


    package com.hope.day01;

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

    public class HelloWorld {
        public static void main(String[] args) throws IOException {
            /*System.out.println("请输入需要抓取文件的源");
            Scanner sc = new Scanner(System.in);
            String src = sc.next();*/

            //数据源
            ArrayList<String> list = new ArrayList<>();
            for (int i = 1; i < 8; i++) {
                String str = "E:\C" + i + "-0H.txt";
                File f = new File(str);
                InputStream is = new FileInputStream(f);
                InputStreamReader isr = new InputStreamReader(is,"gb2312");
                BufferedReader br = new BufferedReader(isr);


                String title = str.substring(3);
                //把文件的名称存放到集合中去
                list.add(title);
    //            System.out.println(title);

                //读文件的内容,存放到结合中去
                String line;
                for (int j = 0; (line = br.readLine()) != null; ++j) {
                  if (j == 79 || j == 80) {
                        //把读出的文件放到集合中去
                        list.add(line);
                       //System.out.println(line);
                    }
                }
                br.close();
            }
            //从集合中写出数据
            String goal = "E:\my.xlsx";
            OutputStream os = new FileOutputStream(goal);
            OutputStreamWriter osw = new OutputStreamWriter(os,"gb2312");
            BufferedWriter bw = new BufferedWriter(osw);
            for (int i = 0; i < list.size(); i++) {
                String str = list.get(i);
                try {
                    System.out.println(str);
                    bw.write(str);
                    bw.newLine();
                    bw.flush();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }

            }
            bw.close();
        }
    }
  • 相关阅读:
    spring boot 配置时区差别
    概率期望
    Euler函数与Euler定理
    素数&筛法
    等差子序列
    8.19 T2
    8.19 T1
    量化交易
    挺进

  • 原文地址:https://www.cnblogs.com/newcityboy/p/11191367.html
Copyright © 2020-2023  润新知