如何从文件中读取数据 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(C:\\laoniu.txt)));然后用br.readLine() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main { System.out.println("==从文件获得输入=="); try { BufferedReader in=new BufferedReader(new FileReader("demo.out")); temp=""; String s=new String(); while((s=in.readLine())!=null) temp+=s+"\n"; in.close();//关闭输入流 System.out.println(temp); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } BufferedReader in=new BufferedReader(new FileReader("demo.out"));//demo.out是你的文件名 import java.io.*;class E{ public static void main(String args[]) { int b; byte buffer[]=new byte[2500]; try{ FileInputStream readfile=new FileInputStream("E.java"); b=readfile.read(buffer,0,2500); try { String str=new String(buffer,0,b,"Default"); System.out.println(str); } catch(UnsupportedEncodingException e) { System.out.println(" the encoding was not found:"+e); } } catch(IOException e) {System.out.println("File read Error "); } }} 为什么我的servlet init方法无法执行??附代码 小弟初学java socket,想知道什么是长连接,什么是短连接。 如何在StringBuffer中判断是否含有某一子串 求一段代码,能够读取目录下的所有文件 高分求助,JDOM build(InputStream)问题! 关于类的设计 关于文件操作中 创建目录的问题 ??JComboBox实现类似于HTML的select一般是怎么做的,就是有一个显示值有一个实际值 初始化的问题 Java是我见过的最烂的语言! 100分求Rational XDE Developer for Java V2003版下载 为什么在类中这样声名赋值不行?
{
System.out.println("==从文件获得输入==");
try
{
BufferedReader in=new BufferedReader(new FileReader("demo.out"));
temp="";
String s=new String();
while((s=in.readLine())!=null)
temp+=s+"\n";
in.close();//关闭输入流
System.out.println(temp);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
class E
{ public static void main(String args[])
{ int b;
byte buffer[]=new byte[2500];
try{ FileInputStream readfile=new FileInputStream("E.java");
b=readfile.read(buffer,0,2500);
try { String str=new String(buffer,0,b,"Default");
System.out.println(str);
}
catch(UnsupportedEncodingException e)
{ System.out.println(" the encoding was not found:"+e);
}
}
catch(IOException e)
{System.out.println("File read Error ");
}
}
}