我正在尝试使用netbeans在java中读取tamil文本文件。我得到的输出只是空白的小盒子。 我的重点是我需要阅读泰米尔文本文件,每个句子需要拆分为单词。下面给出的代码请仔细检查并给我建议如何获得它。
package javaapplication6;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Character.UnicodeBlock;
class words {
private static String[] words;
private static String[] word;
public boolean isTamil(String text){
boolean result = true;
UnicodeBlock tamilBlock = UnicodeBlock.forName("TAMIL");
for(int i=0; i<text.length(); i++){
UnicodeBlock charBlock = UnicodeBlock.of(text.charAt(i));
if(!tamilBlock.equals(charBlock)){
result = false;
}
}
return result;
}
public static void split (String[] query, String[] words) throws IOException {
String s = "This is a sample sentence.";
String[] word = s.split("\\s+");
for (int i = 0; i < words.length; i++) {
// You may want to check for a non-word character before blindly
// performing a replacement
// It may also be necessary to adjust the character class
word[i] = word[i].replaceAll("", "");
}
}
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic hereString fileName="W:/head.txt";
FileInputStream fstream = new FileInputStream("W:/first.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
split(word,words);
System.out.println (strLine);
}
br.close();
}
}
答案 0 :(得分:0)
这是因为它的字符编码问题。像IDE这样的Netbeans将使用默认的OS编码,因此它将打印框或其他有趣的字符。
可能的解决方案是将您的角色编码设置为 UTF-8
如果您还没有看到它,请打开项目窗格(Window&gt; Projects) 在树视图单击中右键单击项目名称 属性确保菜单项&#34;来源&#34;在左边是 突出显示你应该看到&#34;编码:&#34;和旁边的选择框。 点击确定。
进行。