将Data.txt中的第一列数据提取出来,放入dest.txt文件中
import java.io.*;
import java.util.Arrays;
public class SelectByColumn {
public static void main(String[] args) {
SelectByColumn sbc = new SelectByColumn();
try {
sbc.selectByColumn();
} catch (IOException e) {
e.printStackTrace();
}
}
public void selectByColumn() throws IOException {
File srcFile = new File(".\\src\\Data.txt");
File destFile = new File(".\\src\\dest.txt");
FileReader fr = new FileReader(srcFile);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(destFile);
BufferedWriter bw = new BufferedWriter(fw);
String data;
while ((data=br.readLine()) != null){
bw.write(data.split("\\s+")[1]+"\n");
System.out.println(Arrays.toString(data.split("\\s+")));
}
bw.close();
br.close();
}
}
Data.txt文件![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c6225c815fd0ea45290c2eba50fe7492.png)
dest文件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a5ac235a26905b85f1662e90cbbec0ab.png)