try {
bb = new BufferedReader(new InputStreamReader(
new FileInputStream(new File("F:\\测试2.txt"))));
String string = null;
while((string = bb.readLine()) != null) {
int ll = Integer.valueOf(string);
System.out.println(ll);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}finally {
try {
bb.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}文件第一行存了1,第二行存了3,为什么抛出java.lang.NumberFormatException,没有其他的字符啊
bb = new BufferedReader(new InputStreamReader(
new FileInputStream(new File("F:\\测试2.txt"))));
String string = null;
while((string = bb.readLine()) != null) {
int ll = Integer.valueOf(string);
System.out.println(ll);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}finally {
try {
bb.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}文件第一行存了1,第二行存了3,为什么抛出java.lang.NumberFormatException,没有其他的字符啊
解决方案 »
- java可以识别一台电脑是不是连着打印机吗
- JFrame添加组件
- 大侠们帮忙啊
- 有几个问题不明白,请指教~~!
- 请问是jdk的bug还是我的理解问题,关于日期的问题,请帮忙解答一下?
- socket 广播问题!请高手进来指点一下 !谢谢了!
- 帮我看看这段代码!!!谢谢
- HttpClient client = new HttpClient();??
- 那位能提供Forte Enterprise Edition(3.0)的序列号和JPad Pro4.4 Build644 的序列号?
- 大家能否讲一讲怎样继承基类的synchronized方法,谢谢
- 配置jdk7环境时为什么总无法加载主类 com.sun.tools.javac.Main?大家帮忙看看
- java语义问题
测试了一下这段代码如果文件存放的数据都是数字字符,是可以正常运行的。
仅供参考package com.study.nio;import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;public class Answer50
{ public static void main(String[] args)
{
// TODO Auto-generated method stub
BufferedReader bb = null;
try
{
bb = new BufferedReader(new InputStreamReader(new FileInputStream(
new File("F:\\测试2.txt"))));
String string = null;
while ((string = bb.readLine()) != null)
{
int ll = Integer.valueOf(string);
System.out.println(ll);
}
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
bb.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} }}
while ((string = bb.readLine()) != null && string.trim().length()!=0)
{
int ll = Integer.valueOf(string);
System.out.println(ll);
}
&& string.matches("\\d+"))
{
int ll = Integer.valueOf(string);
System.out.println(ll); }