Java 怎样从文件中读入 int 数字,貌似 IOStream 不行啊 IOStream 是按字节读取的,所以读到的不是确切的数字,显示的有时候是ASCCII码我的解决方法是,先用String读入,然后再转成INT数字,有没有更直接的方法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用别的也得转,你的方法可以。如果直接按子节读取后,在把ASCCII码转化成数字,这样叶挺麻烦的。 [code]public class ReadIntTest { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("c:\\temp\\int.txt"); InputStreamReader isr = new InputStreamReader(fis); LineNumberReader lnr = new LineNumberReader(isr); String s = null; int i; while ((s = lnr.readLine()) != null) { i = Integer.parseInt(s); System.out.println("The decimal read: " + i); } } catch (Exception e) { e.printStackTrace(); } }}[/code]int.txt中每行一个数字 public class ReadIntTest { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("c:\\temp\\int.txt"); InputStreamReader isr = new InputStreamReader(fis); LineNumberReader lnr = new LineNumberReader(isr); String s = null; int i; while ((s = lnr.readLine()) != null) { i = Integer.parseInt(s); System.out.println("The decimal read: " + i); } } catch (Exception e) { e.printStackTrace(); } }} 请教一个算法(将任意字符串转换为1-100的数字) preparedStatement 问题2----很玄乎的问题--喜欢挑战的进来 【JMF 】为什么JMF不能播放MP3格式的文件(附代码) 有哪位有导入导出xml文件的代码 easy thing!!!!!!!!! 有没有分析HTML文件的好方法??? 怎么样才能再关闭JFrame时,执行我自定义的一些方法?(在线等待) 看看这个问题怎么办 android 开发 项目前期用的32位jdk 后期可以换成64位jdk吗? java非常简单的问题(用swing做计算器) 我想把txt文本转换2进制文件。急! 请教高手一个简单的问题,刚学java。
麻烦的。
public class ReadIntTest { public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("c:\\temp\\int.txt");
InputStreamReader isr = new InputStreamReader(fis);
LineNumberReader lnr = new LineNumberReader(isr);
String s = null;
int i;
while ((s = lnr.readLine()) != null) {
i = Integer.parseInt(s);
System.out.println("The decimal read: " + i);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
[/code]
int.txt中每行一个数字
public class ReadIntTest { public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("c:\\temp\\int.txt");
InputStreamReader isr = new InputStreamReader(fis);
LineNumberReader lnr = new LineNumberReader(isr);
String s = null;
int i;
while ((s = lnr.readLine()) != null) {
i = Integer.parseInt(s);
System.out.println("The decimal read: " + i);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}