java - java程序在Windows JRE中运行时出现的问题

标签 java windows string unicode


我用java写了一个程序。
在程序的一部分中,它从网页中提取字符串数字并将其转换为整数。 这在linux下工作没有问题。 在 Windows 中,当我从 Netbeans 的运行/调试选项运行程序时,它可以正常工作;
但是当我从 Windows 和 JRE 运行它时,它不起作用! (它错误地提取了该数字)。
这是代码的一部分:

subcatPagesCount=0;
subcatPagesCount=Integer.parseInt(cutstring(CM.getResult(),"( صفحه 1 از "," )").trim());
lblPagesCount.setText(""+subcatPagesCount);

而“cutstring”方法是:

private String cutstring(String in,String from,String to){
    int st=in.indexOf(from)+from.length();
    return in.substring(st,in.indexOf(to,st));
}

它抛出:

java.lang.NumberFormatException: For input string: "tml PUBLIC "-//W3C//DTD XHTM
L 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ
e" content="text/html;charset=UTF-8" /><title>کامپیوتر :: کامپیوت
ر و  قطعات - istgah.com </title><meta name="keywords" content=",istgah,ا
یستگاه,نیازمندیها , آگهی , تبلیغات , ایران" /><m
eta name="description" content="┌⌐╪º┘à┘╛█î┘ê╪¬╪▒ :: ┌⌐╪º┘à┘╛█î┘ê╪¬╪▒ ┘ê  ┘é╪╖╪╣╪
º╪¬ - istgah.com" /><base href="http://www.istgah.com/" /><link rel="stylesheet"
 type="text/css" href="layout/templates/istblue/css/firev4.css" /><link rel="sty
lesheet" type="text/css" href="layout/templates/istblue/css/style2.css" /></head
><body>  <div style="width:980px; float:right; " dir="rtl" >    <div style="widt
h:213px; height:89px; float:right; " dir="rtl" >          <a href="http://www.is
tgah.com/" >        <img border="0" alt="istgah.com" width="213" height="39" ali
gn="top" src="layout/blue/hr_top_right.gif" />      <img border="0" alt="istgah.
com" width="187" height="50" align="top" src="layout/blue/hr_top_right2.gif" />
  </a>    <div style="display:none;">       <img border="0" alt="" width="0" hei
ght="0" align="top" src="layout/blue/hr_top_right_back.gif" />    </div>
</div>    <div align="right" style="width:767px; height:39px; float:left; backgr
ound-image:url(layout/blue/hr_top_right_back.gif); " dir="rtl" >
<div style="width:360px; float:right; padding-top:17px; " >               <a hre
f="http://www.istgah.com">╪╡┘?╪¡┘ç ╪º╪╡┘ä┘è</a> |                 <a href="http:
//www.istgah.com/province/">استانها</a> |                  <a href="http:
//www.istgah.com/advertise/">نسخه قديم</a> |              <a href="http:
//www.istgah.com/user/">ثبت‌نام</a> |             <a href="http://www.is
tgah.com/contactus/">تماس باما</a>              </div>          <div ali
gn="left" style="width:90px; float:right; padding-top:17px; " >           <font
color="blue" >  </font>         </div>          <div align="left" style="width:3
00px; float:right; padding-top:17px; " >                        ╪º┘à╪▒┘ê╪▓: ΓǬ┌
å┘ç╪º╪▒╪┤┘å╪¿┘ç╪î █▓█╡ ╪º╪│┘?┘å╪» █▒█│█╕█╣ΓǼ           </div>  </div>    <div a
lign="right" style="width:767px; height:50px; float:left; " dir="rtl" >
<div style="width:260px; float:right; padding-top:20px; " >               <form
action="http://www.istgah.com/search/ " method="get">                   جستج
و:                     <input name="stext" class="inputbox" size="25" />
                <input type="image" src="layout/go.gif" align="top" />
  </form>               </div>          <div style="width:500px; float:right; "
>                 <table border="0" width="500px" cellspacing="0" class="mc" dir
="rtl" >  <tr>    <td>    <a href="http://www.istgah.com/fireview/computer/">

.....

http://www.istgah.com/firekeys/key_3551/" > samsung</a> - <a href="http://www.is
tgah.com/firekeys/key_136241/" > هارد اکسترنال</a> - <a href="http:/
/www.istgah.com/firekeys/key_3066/" > ┘?╪▒┘ê╪┤ ┌⌐╪º┘à┘╛█î┘ê╪¬╪▒</a> - <a href="h
ttp://www.istgah.com/firekeys/key_1535/" > acer</a> - <a href="http://www.istgah
.com/firekeys/key_13206/" > رایتر</a> - <a href="http://www.istgah.com/fire
keys/key_3100/" > ساعت</a> - <a href="http://www.istgah.com/firekeys/key_625
08/" > مودم adsl</a> - <a href="http://www.istgah.com/firekeys/key_3123/" >
ضبط</a> - <a href="http://www.istgah.com/firekeys/key_203/" > موبایل</a
> - <a href="http://www.istgah.com/firekeys/key_1276/" > laptop</a> - <a href="h
ttp://www.istgah.com/firekeys/key_7199/" > msi</a> - <a href="http://www.istgah.
com/firekeys/key_2270/" > monitor</a> - <a href="http://www.istgah.com/firekeys/
key_321385/" > 5200</a> - <a href="http://www.istgah.com/firekeys/key_807/" > cd
</a> - <a href="http://www.istgah.com/firekeys/key_1870/" > ups</a> - <a href="h
ttp://www.istgah.com/firekeys/key_927/" > تلویزیون</a> - <a href="http:/
/www.istgah.com/firekeys/key_2079/" > مادربرد</a> - <a href="http://www.i
stgah.com/firekeys/key_1723/" > sony</a> - <a href="http://www.istgah.com/fireke
ys/key_532/" > بازی</a> - <a href="http://www.istgah.com/firekeys/key_846/"
> cool disk</a> - <a href="http://www.istgah.com/firekeys/key_51650/" > ╪º┘ä ╪│█
î ╪»█î</a> - <a href="http://www.istgah.com/firekeys/key_51/" > ╪»┘ê╪▒╪¿█î┘å ╪»█
î╪¼█î╪¬╪º┘ä</a> - <a href="http://www.istgah.com/firekeys/key_13/" > ┌⌐╪º┘à┘╛█î┘
ê╪¬╪▒</a> - <a href="http://www.istgah.com/firekeys/key_1766/" > ╪¿╪º╪¬╪▒█î</a>
- <a href="http://www.istgah.com/firekeys/key_3454/" > dell</a> - <a href="http:
//www.istgah.com/firekeys/key_12084/" > mp4</a> - <a href="http://www.istgah.com
/firekeys/key_3637/" > ram</a> - <a href="http://www.istgah.com/firekeys/key_381
0/" > کارت کپچر</a> -           <br />      </td></tr>            <tr><t
d align="center" >         <br />          <form action="http://www.istgah.com/s
earch/ " method="get">          <b>جستجوگر هوشمند آگهی‌های
 ایستگاه: </b>           <input name="stext" class="inputbox" size="30" /
>               <input type="image" src="layout/go.gif" align="top" />     </for
m>         <br />         </td></tr>    </table>          <div>         <table w
idth="100%" cellpadding="0" cellspacing="0" class="nls" >               <tr><td
class="ghd" colspan="3" >تازه‌های کامپیوتر :: کامپیوتر
┘ê  ┘é╪╖╪╣╪º╪¬ ( ╪╡┘?╪¡┘ç 1 ╪º╪▓ 84"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at istgahrobot.doscan$Scan.run(doscan.java:536)
        at java.lang.Thread.run(Unknown Source)

有什么问题吗?
谢谢

最佳答案

您可能没有在打开 Unicode 的情况下运行 JRE。尝试使用 file.encoding 选项运行代码:

-Dfile.encoding=UTF8

或者设置JAVA_TOOL_OPTIONS environment variable-Dfile.encoding=UTF8

参见Setting the default Java character encoding?了解更多。

关于java - java程序在Windows JRE中运行时出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5329619/

相关文章:

java - Commons vfs findFiles 虚构文件

java - 单元测试 OSGi 组件

windows - 在没有 Windows 应用商店的情况下交付 UWP 应用程序的首选方式

c# - 在计算机启动时启动 WPF 应用程序

java - 我需要用 Java 编写一个程序,在其中打印网站上的某些内容(如标题),但我需要取出标签

c - 逐字反转字符串

java - session 范围 bean - 如何处理多用户数据

java - 使用内存数据库(例如 SQLite)是否比将所有内容保存在 HashMap 或其他数据结构中更好?

windows - 打开 "Configure advanced user profile properties"的命令 (Windows 7)

python - Python 的 str.format() 方法的默认 kwarg 值