一个简单问题搞不懂了:( 将String str=new String(buff);放到try...catch...内 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try()内的语句可能执行不到(如果发生exception),则buff未初始化,即未执行buff=new byte[size] 但是没有发生exception呀怎么也没初始化? 但是没有发生exception呀怎么也没初始化? Long length;int size;try{ byte[] buff; RandomAccessFile file=new RandomAccessFile(f,"r"); length=new Long(file.length()); size=length.intValue(); buff=new byte[size]; file.readFully(buff); String str=new String(buff); System.out.println(str);}catch(IOException ex){ System.out.println("I/O error: "+ex);} 那在try{}中定义德buff是全局变量吗? 改成byte[] buff=null;试试? 在编译的时候会自动判断的你认为没有exception可是在执行过程中说不定就有exception那么你的buff就没有得到初始化同意MicroDirt(微尘)的方法:byte[] buff = null或者你也可以把String str = new String(buff);一句放到try里面 : kellychen(陈慧琳) byte[] buff; try { 你在TRY内NEW的BUFF,只作用于TRY内.TRY外使用就会说你的buff没有初始化 : seal_kh() 同意同意 数组列表 入门者学习门槛:关于要不要钻这个牛角尖 关于NIO设置代理的问题 java string indexof out of range怎么办 java中的多态问题,总是不能很好的去理解 Tom猫中文件名要分大小写? 请教下关于热键的问题 怎样判断是int型还是String型? 运行applet时安装jre出现问题,大侠帮忙! 如何使JOptionPane.showConfirmDialog(null,"thisi asdf","sdffsd",JOptionPane.YES_NO_OPTION);在客户端显示? 谁有corejava包,发一个给我?30相送! 请看看(20分)
怎么也没初始化?
怎么也没初始化?
Long length;
int size;
try
{
byte[] buff;
RandomAccessFile file=new RandomAccessFile(f,"r");
length=new Long(file.length());
size=length.intValue();
buff=new byte[size];
file.readFully(buff);
String str=new String(buff);
System.out.println(str);
}
catch(IOException ex)
{
System.out.println("I/O error: "+ex);
}
中定义德buff是全局变量吗?
试试?
你认为没有exception
可是在执行过程中说不定就有exception
那么你的buff就没有得到初始化同意MicroDirt(微尘)的方法:byte[] buff = null
或者你也可以把String str = new String(buff);一句放到try里面
byte[] buff;
try
{
同意同意