日期:2014-05-20  浏览次数:20712 次

java引用txt内容只能引用一行,如何引用多行?
读取数据库输出excel
想将SQL写在一个TXT中  修改sql.txt就可以不用在代码中修改 直接就能生成不同的excel
但是一直报错,提示表名无效
如果不引用txt内容   直接将SQL语句写入代码就不会报错
又试验了一下,txt中把SQL写在一行也不会报错 
应该就是引用只引用了一行的原因
引用部分代码如下:

public static void main(String[]args){
File qfile = new File("D:/sendexcel/report1/sql1.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(qfile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputStreamReader reader = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(reader );
String query = null;
try {
query = br.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}


代码要怎么修改呢? 最好把修改的部分标出来

------解决方案--------------------

while((query=br.readLine())!=null){
System.out.println(query);
}