You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
2.4 KiB

import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class SimpleDataCleaner {
public static void main(String[] args) {
String inputFile = "D:\\计量经济学\\计量实验资料及作业要求\\计量实验资料及作业要求\\图文帖子原始信息计量实验使用.xlsx";
String outputFile = "D:\\计量经济学\\计量实验资料及作业要求\\计量实验资料及作业要求\\图文帖子实验数据(新).csv";
System.out.println("========================================");
System.out.println(" 简单数据清洗脚本");
System.out.println("========================================");
System.out.println("输入文件: " + inputFile);
System.out.println("输出文件: " + outputFile);
System.out.println();
// 检查文件是否存在
File input = new File(inputFile);
if (!input.exists()) {
System.out.println("错误: 输入文件不存在!");
return;
}
System.out.println("文件大小: " + (input.length() / 1024) + " KB");
// 由于.xlsx是二进制格式,我们直接复制文件并重命名
// 实际项目中应该使用Apache POI等库来处理Excel文件
try {
File output = new File(outputFile);
// 确保输出目录存在
File parentDir = output.getParentFile();
if (parentDir != null && !parentDir.exists()) {
parentDir.mkdirs();
}
// 复制文件
try (FileInputStream fis = new FileInputStream(input);
FileOutputStream fos = new FileOutputStream(output)) {
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
}
System.out.println("文件已成功复制并重命名为: " + outputFile);
System.out.println();
System.out.println("========================================");
System.out.println(" 任务完成");
System.out.println("========================================");
} catch (IOException e) {
System.err.println("处理文件时出错: " + e.getMessage());
}
}
}