|
@@ -5,6 +5,7 @@ import com.miaxis.dict.domain.DictCity;
|
|
|
import com.miaxis.dict.service.IDictCityService;
|
|
|
import com.miaxis.exam.domain.ExamInfo;
|
|
|
import com.miaxis.exam.service.IExamInfoService;
|
|
|
+import net.sourceforge.pinyin4j.PinyinHelper;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
@@ -40,8 +41,8 @@ public class ReadFileNameTest2 {
|
|
|
*/
|
|
|
@Test
|
|
|
public void test() {
|
|
|
- String folderPath = "F:/河南省"; // 替换为你的文件夹路径
|
|
|
- String excelFilePath = "F:/exam_info.xlsx"; // 替换为你的Excel文件路径
|
|
|
+ String folderPath = "H:/广东省"; // 替换为你的文件夹路径
|
|
|
+ String excelFilePath = "H:/exam_info.xlsx"; // 替换为你的Excel文件路径
|
|
|
|
|
|
try {
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
@@ -81,7 +82,7 @@ public class ReadFileNameTest2 {
|
|
|
|
|
|
private void traverseFolders(File folder, Sheet sheet, int rowIndex) {
|
|
|
String province = folder.getName();
|
|
|
- String provinceId = "41";
|
|
|
+ String provinceId = "44";
|
|
|
String city = null;
|
|
|
String cityId = null;
|
|
|
String county = null;
|
|
@@ -98,7 +99,7 @@ public class ReadFileNameTest2 {
|
|
|
|
|
|
for (int j = 0; j < dictCityList.size(); j++) {
|
|
|
cityId = dictCityList.get(j).getCode();
|
|
|
- if (cityId.startsWith("41")) {
|
|
|
+ if (cityId.startsWith("44")) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -152,20 +153,30 @@ public class ReadFileNameTest2 {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public File[] sortFiles(File[] files) {
|
|
|
-
|
|
|
+ public static File[] sortFiles(File[] files) {
|
|
|
if (files != null) {
|
|
|
- // 使用Collator类创建一个特定语言环境的排序器(这里使用中文)
|
|
|
Collator collator = Collator.getInstance(Locale.CHINA);
|
|
|
// 使用Comparator.comparing方法结合Lambda表达式按文件名的拼音首字母排序
|
|
|
- Arrays.sort(files, Comparator.comparing(file -> file.getName(), collator));
|
|
|
+ //Arrays.sort(files, Comparator.comparing(file -> file.getName(), collator));
|
|
|
+ // 使用Pinyin4j将汉字转换为拼音,并按拼音进行排序
|
|
|
+ Arrays.sort(files, Comparator.comparing(file -> getPinyin(file.getName()), collator));
|
|
|
+ }
|
|
|
+ return files;
|
|
|
+ }
|
|
|
|
|
|
- // 输出排序后的文件名
|
|
|
- for (File file : files) {
|
|
|
- System.out.println(file.getName());
|
|
|
+ // 使用Pinyin4j将汉字转换为拼音
|
|
|
+ private static String getPinyin(String hanzi) {
|
|
|
+ StringBuilder pinyin = new StringBuilder();
|
|
|
+ for (char ch : hanzi.toCharArray()) {
|
|
|
+ String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(ch);
|
|
|
+ if (pinyinArray != null && pinyinArray.length > 0) {
|
|
|
+ pinyin.append(pinyinArray[0]);
|
|
|
+ } else {
|
|
|
+ // 如果无法获取拼音,则原样输出汉字
|
|
|
+ pinyin.append(ch);
|
|
|
}
|
|
|
}
|
|
|
- return files;
|
|
|
+ return pinyin.toString();
|
|
|
}
|
|
|
|
|
|
|