Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法读取Java中的阿拉伯语文本文件_Java_File_Text - Fatal编程技术网

无法读取Java中的阿拉伯语文本文件

无法读取Java中的阿拉伯语文本文件,java,file,text,Java,File,Text,我尝试使用Java读取阿拉伯语文本,但扫描仪看不到任何元素,因此读取失败,尽管LineNumberReader识别文本文件中的行 我在英文文本上尝试了相同的代码,效果很好 我正在使用netbeans 7.0.1 这是我的密码: public class ReadFile { private int number_of_words; private File f1; private String array[][],lines[]; private Scanner

我尝试使用Java读取阿拉伯语文本,但扫描仪看不到任何元素,因此读取失败,尽管LineNumberReader识别文本文件中的行

我在英文文本上尝试了相同的代码,效果很好

我正在使用netbeans 7.0.1

这是我的密码:

public class ReadFile {
    private int number_of_words;
    private File f1;
    private String array[][],lines[];
    private Scanner scan1;

    public ReadFile(String sf1) throws FileNotFoundException
    {
        f1=new File(sf1);
        scan1=new Scanner(f1);

    }

    public String[][] getA()
    {
        return array;
    }

    public void read() throws IOException
    {
        int counter=0,i=0;

        LineNumberReader  lnr = new LineNumberReader(new FileReader(f1));
        lnr.skip(Long.MAX_VALUE);
        number_of_words=lnr.getLineNumber();
        array = new String[2][number_of_words];
        lines = new String[number_of_words];
        while(scan1.hasNext())
      {
        String temp;
        temp=scan1.nextLine();
        lines[counter++] = temp;
                        System.out.println(lines[counter-1]+"\t"+lines.length);

      }

       Arrays.sort(lines);
       counter=0;

       while(i<lines.length)
       {
           String temp = lines[i++];
           StringTokenizer tk=new StringTokenizer(temp,"\t");

           array[0][counter] = tk.nextToken();
           array[1][counter++] = tk.nextToken();
       }
     }
 } 

尝试使用以下命令读取文件:

FileInputStream fis = new FileInputStream(f1);
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(fis, "UTF-8"));

读取文件时需要使用右侧。默认情况下,扫描仪使用系统编码。在读取数据特殊字符时,需要使用正确的字符编码

scan1=new Scanner(f1, "UTF-8");
如果UTF-8不起作用,您需要尝试使用特定于阿拉伯语的编码


以下是一些可能有用的链接,

这很可能就是您正在寻找的内容:

Scanner(System.in, "UTF-8")

NetBeans在这里是不相关的,所以我将删除该标记。此外,接受更多的答案-你的比率相当低。