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();
}
}
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();
}
}