java实现中英⽂翻译_java实现简单的英⽂⽂本单词翻译器功能
⽰例
本⽂实例讲述了java实现简单的英⽂⽂本单词翻译器功能。分享给⼤家供⼤家参考,具体如下:
直接上代码:
package fanyi;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
下载翻译器英文翻中文import java.util.StringTokenizer;
public class text {
public static void handle(String eString) throws IOException {
StringTokenizer st = new StringTokenizer(eString,",!' '.;");
while(st.hasMoreElements()) {
String sText;
sText = st.nextElement().toString();
//System.out.println(sText);
String encoding="GBK";
String filepath="fanyi\\src\\fanyi\\";
File file=new File("G:\\workspace4\\fanyi\\src\\fanyi\\");
// System.out.println("2222");
if(file.isFile() && ists()){ //判断⽂件是否存在
//System.out.println("1111");
InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = adLine()) != null){
//System.out.println(lineTxt);
//System.out.println("333");
String().equals(sText)){
System.out.println(sText + adLine());
}
}
read.close();
}
}
}
public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in);
System.out.println("请输⼊英⽂⽂本:");
String eText = sc.nextLine();
handle(eText);
//System.out.println(eText);
}
}
⽂件结构如下:
运⾏结果:
希望本⽂所述对⼤家java程序设计有所帮助。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。