/**
* Get the specified file content
* If any exception found,return ""
* @param path the name of the file location
* @param isReadLine if true,add line break on each line
* @return
*/
public static String getFileContent(String path,boolean isReadLine)
{
String tmp = "";
java.io.RandomAccessFile raf;
try
{
File f = new File(path);
if( (!f.isFile()) && (!f.exists()))
{
System.out.println("Invalid file:" + path);
return tmp;
} raf = new java.io.RandomAccessFile(path,"r");
String s = "";
while((s = raf.readLine()) != null)
{
//System.out.println(tmp);
tmp += s;
if(isReadLine)
tmp += "\n";
}
raf.close();
return tmp;
}catch(java.io.FileNotFoundException e)
{
return tmp;
}
catch(java.io.IOException e)
{
return tmp;
} }
}out.println( getFileContent("c:\\a\\a.txt"),true) );
* Get the specified file content
* If any exception found,return ""
* @param path the name of the file location
* @param isReadLine if true,add line break on each line
* @return
*/
public static String getFileContent(String path,boolean isReadLine)
{
String tmp = "";
java.io.RandomAccessFile raf;
try
{
File f = new File(path);
if( (!f.isFile()) && (!f.exists()))
{
System.out.println("Invalid file:" + path);
return tmp;
} raf = new java.io.RandomAccessFile(path,"r");
String s = "";
while((s = raf.readLine()) != null)
{
//System.out.println(tmp);
tmp += s;
if(isReadLine)
tmp += "\n";
}
raf.close();
return tmp;
}catch(java.io.FileNotFoundException e)
{
return tmp;
}
catch(java.io.IOException e)
{
return tmp;
} }
}out.println( getFileContent("c:\\a\\a.txt"),true) );
解决方案 »
- JSP基础问题!!求解!!!
- jsp传递过来参数为中文,程序中接收过来是乱码,如何处理呢?
- 一个奇怪的中文乱码问题(长度为奇数时最后一个字符会出现乱码)
- 如何实现在网页中在线编辑EXCEL表格,然后保存到服务器中?(不使用<input type="file">标签来选择文件这种形式)
- JSF1.1 自定义组件的小问题
- 如何读取sql中类型为image字段的内容?读取到文件中或是直接打开求源码!急急急!!高分求答案
- 我的fastreport模板如何连接数据库啊?
- actionform 中文变成了???? 求解(急急急!!)
- 路径问题
- jsp和servlet是什么关系,有什么区别?
- 启动tomcat的时候,老是说out of 环境空间,有谁知道怎么回事?
- 强制输出结束
http://192.168.0.1/aa/a.txt
String realpath = sct.getRealPath("");
realpath为当前发布目录的绝对路径。下面就不用我说了吧! :)