当前位置: 技术问答>java相关
在jsp中如何读取文本文件中的字符?急!
来源: 互联网 发布时间:2015-06-12
本文导语: try{ FileInputStream file1 = new FileInputStream("xx.txt"); BufferedReader bReader = new BufferedReader(new InputStreamReader(file1)); String password if((password = bReader.readLine())== null) password=null; bRead...
try{
FileInputStream file1 = new FileInputStream("xx.txt");
BufferedReader bReader = new BufferedReader(new InputStreamReader(file1));
String password
if((password = bReader.readLine())== null)
password=null;
bReader.close();
file1.close();
}catch(IOException e){
out.print(e);
}
上面的程序在java中能读取,可是在jsp中不能读取,报告“pass1java.io.FileNotFoundException: xx.txt" (系统找不到指定的路径。) ”
FileInputStream file1 = new FileInputStream("xx.txt");
BufferedReader bReader = new BufferedReader(new InputStreamReader(file1));
String password
if((password = bReader.readLine())== null)
password=null;
bReader.close();
file1.close();
}catch(IOException e){
out.print(e);
}
上面的程序在java中能读取,可是在jsp中不能读取,报告“pass1java.io.FileNotFoundException: xx.txt" (系统找不到指定的路径。) ”
|
|
FileInputStream file1 = new FileInputStream("xx.txt");
中的xx.txt要带全路径如c:\java\allinterface\xx.txt;
中的xx.txt要带全路径如c:\java\allinterface\xx.txt;
|
你可以这样取你的web路径加文件名
String sPath = request.getRealPath("/")+sFileName ;
文件放在web根目录下。
String sPath = request.getRealPath("/")+sFileName ;
文件放在web根目录下。
|
FileInputStream file1 = new FileInputStream("xx.txt");
BufferedReader bReader = new BufferedReader(new InputStreamReader(file1));
======================
BufferedReader bReader = new BufferedReader(file1);
BufferedReader bReader = new BufferedReader(new InputStreamReader(file1));
======================
BufferedReader bReader = new BufferedReader(file1);