1 Star 0 Fork 18

搞机BOI/e_ink_word_card_2in13低成本平替喵喵机

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
java代码支持批量转换.txt 3.14 KB
一键复制 编辑 原始数据 按行查看 历史
package wordsTool;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class FinalTool {
public static String web_add(String word) throws IOException {
URL url = new URL("https://dict.youdao.com/w/"+word+"/#keyfrom=dict2.top");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(),"UTF-8"));//.openStream()
String line,symbol="";
while ((line = reader.readLine()) != null) {
if(line.contains("[")) {
symbol=line.substring(line.indexOf("["),line.indexOf("]")+1);
break;
}
}
reader.close();
return symbol;
}
public static String format(String s) {
String s2="";
s2=s.substring(0,s.indexOf("]")+1);
for(int i=s.indexOf("]")+1;i<s.length();i++) {
s2+=s.charAt(i);
if((i<s.length()-3&&i>0&&((s.charAt(i+1)=='n'&&s.charAt(i+2)=='.')&&s.charAt(i)!=' '||(s.charAt(i+1)=='v'&&(s.charAt(i+3)=='.'||s.charAt(i+2)=='.')&&s.charAt(i)!='d')||((s.charAt(i+1)=='a')&&s.charAt(i+4)=='.'))&&s.charAt(i-1)!=' '&&s.charAt(i)!=' ')){
s2+=" ";
}
}
System.out.println(s2);
return s2;
}
public static void writeTxt(String txtPath, String content) throws InterruptedException {
// for(int i=0;i<5;i++) {
// for(int j=0;j<10;j++) {
// System.out.println("!");
// }
// System.out.println();
// }
System.out.println("开始写入....");
TimeUnit.SECONDS.sleep((int)Math.random()*3);
FileOutputStream fileOutputStream = null;
File file = new File(txtPath);
try {
if (file.exists()) {
file.createNewFile();
}
fileOutputStream = new FileOutputStream(file,true);
fileOutputStream.write(content.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static List<File> getFiles(String path) {
File root = new File(path);
List<File> files = new ArrayList<File>();
if (!root.isDirectory()) {
files.add(root);
} else {
File[] subFiles = root.listFiles();
for (File f : subFiles) {
files.addAll(getFiles(f.getAbsolutePath()));
}
}
return files;
}
public static void main(String[] args) throws Exception {
String path ="";
List<File> files = getFiles("D:/csvs");
for (File file : files) {
System.out.println("当前文档:"+file.getName());
path ="d:/format/"+ file.getName()+".txt";
BufferedReader br = new BufferedReader(new FileReader(file));
String str = "", s = "" ;
int f = 0;
while ((s = br.readLine()) != null) {
if(s.contains("\"")) {
f++;
}
str+=s;
if(f%2==0) {
str=str.replaceFirst(",", web_add(str.substring(0,str.indexOf(","))));
str = str.replace("\"", "" );
str= format(str).replaceAll(";", ";");
str+="\n";
writeTxt(path,str);
// TimeUnit.SECONDS.sleep((int)Math.random()*3);
str="";
}
}
br.close();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/HJDIY/e_ink_word_card_2in13.git
git@gitee.com:HJDIY/e_ink_word_card_2in13.git
HJDIY
e_ink_word_card_2in13
e_ink_word_card_2in13低成本平替喵喵机
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385