提交 d8d7cdbd 编写于 作者: heeeeeyy's avatar heeeeeyy

上传新文件

上级 fc5949a1
package com.bluelake;
import com.bluelake.utils.LevenshteinAlgorithm;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Main {
static final String ENCODING = "utf-8";
static final String ANSWER_FILE = "D:\\text\\Article_repetition_answer.txt";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入原论文的地址:");
String aAddress = sc.nextLine();
System.out.println("请输入抄袭论文的地址:");
String bAddress = sc.nextLine();
String a = readFile(aAddress);
String b = readFile(bAddress);
System.out.println("论文查重结果已经存储在"+ANSWER_FILE);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String result = df.format(System.currentTimeMillis())+"\n"+aAddress+"与"+bAddress+ "的相似度为 : "
+ String.format("%.3f", LevenshteinAlgorithm.Levenshtein(a, b)*100)+"%";
writeAnswer(result);
System.out.println(result); }
static public String readFile(String path) {
File file = new File(path);
try {
InputStreamReader inputStreamReader=
new InputStreamReader(new FileInputStream(file), ENCODING);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
if (file.isFile() && file.exists()) {
String line;
StringBuilder stringBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
return stringBuilder.toString();
} else {
System.out.println("该输入文件不存在");
}
inputStreamReader.close();
} catch (Exception e) {
System.out.println("文件读取失败");
}
return null; }
static public void writeAnswer(String str) {
File answer_file=new File(ANSWER_FILE);
if(!answer_file.exists()){
try {
answer_file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}}
byte[] bytes =str.getBytes();
int b=bytes.length;
FileOutputStream fileOutputStream;
try {
fileOutputStream = new FileOutputStream(answer_file);
fileOutputStream.write(bytes,0,b);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册