The book here is written in charactorprocess (file file, String destfile)
I changed it here. (string file, String destfile)
One representing the existing file and the file to be created
Code:
package com;
Import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.File;
Import Java.io.FileReader;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.util.HashMap;
public class FileRead {
public static string replace (string line {
//Create a HASHMAP store the corresponding relationship between full-width and half-width characters
HashMap map = new HashMap ();
map.put (",", ",");
map.put (".
", ".");
Map.put ("(", "<");
Map.put ("", ">");
Map.put ("|", "|");
Map.put ("", "<");
Map.put ("" "," > ");
Map.put ("[", "[");
Map.put ("]", "]");
Map.put ("? ", "?
");
Map.put ("" "," \ "");
Map.put (":", ":");
Map.put ("﹑", ",");
Map.put ("(", "(");
Map.put (")", ")");
Map.put ("" "," [");
Map.put ("" ","] ");
Map.put ("-", "-");
Map.put (" ̄", "~");
Map.put ("! ", "!");
Map.put ("'", "'");
Map.put ("1", "1");
Map.put ("2", "2");
Map.put ("3", "3");
Map.put ("4", "4");
Map.put ("5", "5");
Map.put ("6", "6");
Map.put ("7", "7");
Map.put ("8", "8");
Map.put ("9", "9");
int length = Line.length ();
for (int i = 0; i < length; i++) {
String Charat = line.substring (i, i + 1);
if (Map.get (charat) = null) {
line = Line.replace (Charat, (String) Map.get (Charat));
}
}
return line;
}
public static File charactoprocess (string string, string destfile) {
try{
Create an output stream for writing new files
BufferedWriter writer = new BufferedWriter (new FileWriter (DestFile));
Creates an input stream. for reading files
BufferedReader reader = new BufferedReader (new FileReader (string));
String line = Reader.readline ();
while (line! = null) {
Call the Replace method to replace all full-width characters
String newline = replace (line);
Writes the replaced string to a new file
Writer.write (newline);
Write line delimiter
Writer.newline ();
line = Reader.readline ();
}
Reader.close ();
Writer.close ();
}catch (IOException e) {
E.printstacktrace ();
}
return new File (destfile);
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
FileRead B = new FileRead ();
B.charactoprocess ("E:\\lucene project \ \ Steel is how to practice". txt "," E:\\lucene project \ \ target file. txt ");
}
}
Use Lucene to change the font format of the text and then output it to a new file.