Javaプログラミングは、2つのテキストファイルに対して、同じ点と異なる点をマークする方法を実現します。
本論文の例は、Javaプログラミングの実施比を2つのテキストファイルに記述し、同じ点と異なる点をマークする方法を示している。皆さんに参考にしてあげます。具体的には以下の通りです。
使用需要:
ファイル1の中は比較が必要な内容で、ファイル2は比較されたテキストであり、現在はファイル1の各行のテキストがファイル2に存在しているかどうかを見つける必要があります。同じであれば、結果ファイルの中で出力します。ファイル1のどの行がファイル2のどの行と同じですか?逆に同じではないなら、出力ファイル1のどのラインが同じではないですか?
Javaコードは、出力されたのはレスリングt.txtファイルで、このファイルの行番号はファイル1と一致しています。したがって、reultの中のある行の結果は対応するファイル1の行のデータがファイル2で比較された後の結果です。
(注意文書1とファイル2は、行ごとの内容で比較される)
最後に、簡単に見るために、Notepad++を通して見ることができます。
本論文で述べたように、皆さんのjavaプログラムの設計に役に立ちます。
使用需要:
ファイル1の中は比較が必要な内容で、ファイル2は比較されたテキストであり、現在はファイル1の各行のテキストがファイル2に存在しているかどうかを見つける必要があります。同じであれば、結果ファイルの中で出力します。ファイル1のどの行がファイル2のどの行と同じですか?逆に同じではないなら、出力ファイル1のどのラインが同じではないですか?
Javaコードは、出力されたのはレスリングt.txtファイルで、このファイルの行番号はファイル1と一致しています。したがって、reultの中のある行の結果は対応するファイル1の行のデータがファイル2で比較された後の結果です。
(注意文書1とファイル2は、行ごとの内容で比較される)
最後に、簡単に見るために、Notepad++を通して見ることができます。
package com.it.aron;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* check repetitive text
* @author: aronxu
* @version: 1.0, Sep 22, 2015
*/
public class AutoCheckText {
private static final String FILE_PATH = "D:/text1.txt";
private static final String COMPARED_FILE_PATH = "D:/text2.txt";
private static final String RESULT_FILE_PATH = "D:/result.txt";
public static void main(String[] args) {
System.out.println("======Start Search!=======");
long startTime = System.currentTimeMillis();
// Read first file
File file = new File(FILE_PATH);
File comparedFile = new File(COMPARED_FILE_PATH);
BufferedReader br = null;
BufferedReader cbr = null;
BufferedWriter rbw = null;
try {
br = new BufferedReader(new FileReader(file));
cbr = new BufferedReader(new FileReader(comparedFile));
cbr.mark(90000000);
rbw = new BufferedWriter(new FileWriter(RESULT_FILE_PATH));
String lineText = null;
while ((lineText = br.readLine()) != null) {
String searchText = lineText.trim();
searchAndSignProcess(searchText, cbr, rbw);
}
long endTime = System.currentTimeMillis();
System.out.println("======Process Over!=======");
System.out.println("Time Spending:" + ((endTime - startTime) / 1000D) + "s");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (cbr != null && rbw != null) {
try {
cbr.close();
rbw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
public static void searchAndSignProcess(String searchText, BufferedReader comparedReader, BufferedWriter rbw)
throws IOException {
String lineStr = "-
";
if (searchText == null) {
return;
}
if ("".equals(searchText)) {
rbw.write(lineStr);
return;
}
String lineText = null;
int lineNum = 1;
while ((lineText = comparedReader.readLine()) != null) {
String comparedLine = lineText.trim();
if (searchText.equals(comparedLine)) {
lineStr = "###=Equal:" + lineNum + "=###
";
break;
}
lineNum++;
}
rbw.write(lineStr);
comparedReader.reset();
}
}
text 1.txtの内容:
myaccount.msg.register.register=Registro Personas
myaccount.msg.register.your_company=¿Eres empresa?
myaccount.msg.register.sign_up=Registrate aquí
myaccount.msg.register.fields_compellent=Todos los campos son obligatorios
myaccount.msg.register.account_data=Datos de la cuenta
myaccount.msg.register.email=E-mail:
myaccount.msg.register.confirm_email=Confirma tu E-mail:
myaccount.msg.register.password=Contraseña:
myaccount.msg.register.confirm_password=Confirma tu Contraseña:
myaccount.msg.register.personal_data=Datos personales
myaccount.msg.register.first_name=Nombre:
myaccount.msg.register.last_name=Apellido Paterno:
myaccount.msg.register.middle_name=Apellido Materno:
myaccount.msg.register.country=País de Residencia:
myaccount.msg.register.id_card=Cédula de Identidad:
myaccount.msg.register.genero=Género:
myaccount.msg.register.male=Masculino:
myaccount.msg.register.female=Femenino:
myaccount.msg.register.birth=Fecha de Nacimiento:
myaccount.msg.register.day=Día
myaccount.msg.register.month=Mes
text 2.txtの内容:
myaccount.msg.register.country=País de Residencia:
myaccount.msg.register.confirm_password=Confirma tu Contraseña:
myaccount.msg.register.last_name=Apellido Paterno:
myaccount.msg.register.middle_name=Apellido Materno:
myaccount.msg.register.id_card=Cédula de Identidad:
myaccount.msg.register.genero=Género:
myaccount.msg.register.male=Masculino:
myaccount.msg.register.female=Femenino:
myaccount.msg.register.personal_data=Datos personales
myaccount.msg.register.first_name=Nombre:
result.txt内容:
-
-
-
-
-
-
-
-
-
###=Equal:2=###
###=Equal:12=###
###=Equal:13=###
-
###=Equal:4=###
###=Equal:5=###
###=Equal:1=###
###=Equal:7=###
-
###=Equal:9=###
###=Equal:10=###
###=Equal:11=###
-
-
-
javaアルゴリズムに関する詳細について興味がある読者は、当駅のテーマを見ることができます。「Javaファイルとディレクトリの操作テクニックのまとめ」、「Javaデータ構造とアルゴリズム教程」、「Java操作DOMノード技術のまとめ」、「Javaキャッシュ操作テクニックのまとめ」本論文で述べたように、皆さんのjavaプログラムの設計に役に立ちます。