Use Lucene to change the font format of the text and then output it to a new file.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.