我也遇到过下面的错误在编译时就DataInputStreamDemo我的演示代码: 错误:i = Integer.parseInt(dis.readLine())[已弃用] ..如何解决它?
i= Integer.parseInt(dis.readLine()) [Deprecated]
//其中DIS =参考DataInputStream所OBJ
我也遇到过下面的错误在编译时就DataInputStreamDemo我的演示代码: 错误:i = Integer.parseInt(dis.readLine())[已弃用] ..如何解决它?
i= Integer.parseInt(dis.readLine()) [Deprecated]
//其中DIS =参考DataInputStream所OBJ
原因的方法被弃用:
This method does not properly convert bytes to characters.
解决方案
现有代码:DataInputStream d = new DataInputStream(in);
修改后的代码:BufferedReader d = new BufferedReader(new InputStreamReader(in));
链接只有答案是不鼓励的,因为链接可能会随着时间而死亡。链接很棒,但你的答案应该能够独立存在。 – ataulm
肯定先生,我会记住我未来的帖子。 :) 因为相同的内容被回答我会离开这个帖子,因为这是为了避免重复的答案 –
这些评论将帮助我在将来写更好的答案:)谢谢 –
的javadoc for this method使得它相当清楚它为什么弃用,并有已经很长时间了,并且提出了一个更好的选择。
从的Javadoc引用:
此方法不正确地将字节转换为字符。从JDK 1.1开始,读取文本行的首选方法是通过BufferedReader.readLine()方法。使用该DataInputStream类读取文本行的程序可以被转换通过更换形式的代码来使用BufferedReader类:
DataInputStream d = new DataInputStream(in);
与:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));
语言?版?什么类型是“dis”?链接到在线文档中已弃用的方法,如果您尚未通过阅读文档中的注释来解决问题,那么我们可以建议一种替代方法? – ataulm
java se 1.6,数据类型:DataInputStream dis = new DataInputStream(资源) – Raviteja
java.io.DataInputStream中的readLine()已被弃用 – Raviteja