JSP读取tomcat文件

自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)

http://blog.csdn.net/songylwq/article/details/5771893

//获取服务器根目录  
String serPath = this.getClass().getResource("/").getPath();  
int indTom = serPath.indexOf("Tomcat");  
String be = serPath.substring(0,indTom);  
//处理后得到context.xml文件的绝对路径  
String conf = be + serPath.substring(serPath.indexOf("Tomcat"))
	.substring(0,serPath.substring(serPath.indexOf("Tomcat")).indexOf("/"))
	+ "/conf/context.xml";
//将路径中符号转变成空格,这样得到的conf就是文件的绝对路径
conf = conf.replaceAll("%20", " ");

如何用JSP读取文件夹里的全部文件名及大小类型

http://bbs.chinaunix.net/thread-651343-1-1.html

String path = "./"; //路径
File f = new File(path);
if (!f.exists())
{
        out.println(path+" not exists");
        return;
}

File fa[] = f.listFiles();
for(int i=0;i<fa.length;i++)
{
        File fs = fa[i];
        if (fs.isDirectory())
        {
                out.println(fs.getName()+" [目录]<br />");
        }else{
                out.println(fs.getName()+"<br />");
        }
}

JSP读取TXT文件两例

http://www.java3z.com/cwbwebhome/article/article5/5775.html

  String path = request.getRealPath("/temp"); //取得目录在服务器端的实际位置
  //out.println(path+"<br>");
  FileWriter fw = new FileWriter(path + "\\File.txt"); //建立FileWrite对象,并设定由fw对象变量引用
  //将字串写入文件
  fw.write("大家好!");
  fw.write("祝大家学习jsp愉快!");
  fw.write("希望大家能够深入了解jsp技术!");
  fw.close(); //关闭文件

  FileReader fr = new FileReader(path + "\\File.txt"); //建立FileReader对象,并设定由fr对象变量引用
  BufferedReader br = new BufferedReader(fr); //建立BufferedReader对象,并设定由br对象变量引 
  String Line = br.readLine(); //读取一行数据
  out.println(Line + "<BR>"); //输出读取得的数据
  br.close(); //关闭BufferedReader对象
  fr.close(); //关闭文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值