Java Native语言应用程序在IDE外部无效 [英] Java Native language Application Doesnt work outside IDE

查看:170
本文介绍了Java Native语言应用程序在IDE外部无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用netbeans在java下开发的程序。它有一个文本窗格,用非英语写的文本,并做一些操作,包括保存打开新的.....

I have a program developed under java with netbeans. It has a text pane that takes text written in non English language and do some operation including save open new.....

该程序很好,完成工作完美无缺我从netbeans运行它。但是当我去dist文件夹并运行jar(它应该是可执行文件)时它运行良好但是当我打开以前保存的文件到编辑器时它会显示神秘的字体。

The program was fine and complete worked flawlessly when i run it from netbeans. But when i go to the dist folder and run the jar (which was supposed to be the executable) it runs good but when i open a previously saved file to the editor it shows mysterious fonts.

喜欢 -

লিখ原始输入是<< নতুন_লাইন; $ b $bচলবে(সংখ্যাপ= 0;প<যতটা;প++)

লিখ "The original inputs are" << নতুন_লাইন; চলবে(সংখ্যা প=০;প<যতটা;প++)

成为

à|||||||| - 原始输入是<< à|¨à|¤à§à|¨_à|²à|¾à|‡à|¨; $ b $bà|šà|²à|¬§§‡(à|¸à|,à|-ৠà|¯|||à|ª=à§|;à|ª<à|¯à| ¤à|Ÿà|¾;à|ª++)

লিখ "The original inputs are" << নত�ন_লাইন; চলবে(সংখ�যা প=০;প<যতটা;প++)

另一个有趣的事情是。如果我在编辑器中键入它也工作正常(没有字体问题)。

one more interesting thing is that. If i type in the editor it is also working fine (no font problem).

我使用这两个函数来读写文件

I am using these 2 functions to read and write to file

public void writeToFile(String data,String address)
{
      try{
          // Create file 
    FileWriter fstream = new FileWriter(address);
        BufferedWriter out = new BufferedWriter(fstream);
    out.write(data);
    //Close the output stream
    out.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }

}


public String readFromFile(String fileName) {
   String output="";
    try {
     File file = new File(fileName);
     FileReader reader = new FileReader(file);
     BufferedReader in = new BufferedReader(reader);
     String string;
     while ((string = in.readLine()) != null) {
       output=output+string+"\n";
     }
     in.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
    return output;
 }

我已将文本窗格的字体设置为vrinda正如我所提到的IDE。

I have set the font of the text pane to vrinda which works from within the IDE as i mentioned.

请帮我弄清楚是什么问题。

Please help me identify what is wrong.

当需要原生支持时,我需要做些什么才能发布JAR?

is there something i need to do to publish JAR when native support is required?

推荐答案

尝试更改您的阅读逻辑以使用允许设置编码的InputStreamReader:

Try changing your reading logic to use InputStreamReader which allows setting encoding:

InputStreamReader inputStreamReader = 
  new InputStreamReader(new FileInputStream (file), "UTF-8" );

同时更改您的写入逻辑以使用OutputStreamWriter,它允许设置编码:

Also change your writing logic to use OutputStreamWriter which allows setting encoding:

OutputStreamWriter outputStreamWriter = 
  new OutputStreamWriter(new FileOutputStream (file), "UTF-8" );

这篇关于Java Native语言应用程序在IDE外部无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆