Home > Database > Mysql Tutorial > JSP读取文件实例_MySQL

JSP读取文件实例_MySQL

WBOY
Release: 2016-06-01 14:11:00
Original
1018 people have browsed it

  
//变量声明 
java.lang.String strFileName; //文件名 
java.io.File objFile; //文件对象 
java.io.FileReader objFileReader; //读文件对象 
char[] chrBuffer = new char[10]; //缓冲 
int intLength; //实际读出的字符数(一个中文为一个字符) 



//设置待读文件名 
strFileName = "d:\\test.txt"; 



//创建文件对象 
objFile = new java.io.File(strFileName); 



//判断文件是否存在 
if(objFile.exists()){//文件存在 
//创建读文件对象 
objFileReader = new java.io.FileReader(objFile); 



//读文件内容 
while((intLength=objFileReader.read(chrBuffer))!=-1){ 
//输出 
out.write(chrBuffer,0,intLength); 




//关闭读文件对象 
objFileReader.close(); 

else{//文件不存在 
out.println("下列文件不存在:"+strFileName); 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template