web开发,读取txt文件(程序或本地硬盘)

<%
		//本地硬盘下txt文件
		//String path ="C:\\";   // 这边文件目录需改成相对路径
		//File file = new File(path,"jsp.txt");
		//程序WebContent下目录下txt文件
		String filename2="/txt/";   filename2=this.getServletContext().getRealPath(filename2);
		System.out.println(filename2);

		//String path ="../txt/";   // 这边文件目录需改成相对路径
		File file = new File(filename2,"jsp.txt");
		FileReader fr = new FileReader(file);  //字符输入流
		BufferedReader br = new BufferedReader(fr);  //使文件可按行读取并具有缓冲功能
		//StringBuffer strB = new StringBuffer();   //strB用来存储jsp.txt文件里的内容
		String str = br.readLine();
		int num = 0;
		List<String> lists=new ArrayList<String>(); 
		lists.add(str);
		while(str!=null){
			//strB.append(str).append("<br>");   //将读取的内容放入strB
			str = br.readLine();
			lists.add(str);
		}
		br.close();    //关闭输入流
	%>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值