JSP skills - read file instances

xiaoxiao2021-03-06  98

<% @ Page ContentType = "text / html; charset = GB2312"%>

<%

// Variable declaration

Java.lang.string strfilename; // file name

Java.io.file objfile; // file object

Java.io.fileReader objfileReader; // read file object

Char [] chrbuffer = new char [10]; // buffer

INT INTLENGTH; / / The number of characters read out (one Chinese is a character)

// Set the file name to be read

Strfilename = "d: //test.txt";

// Create a file object

Objfile = new java.io.file (strfilename);

/ / Judgment if the file exists

IF (Objfile.exists ()) {// file exists

// Create a read file object

ObjfileReader = new java.io.fileReader (Objfile);

// read file content

While (intlength = objfilereader.read (chrbuffer))! = - 1) {

// output

Out.write (chrbuffer, 0, intlength);

}

// Close the read file object

ObjfileReader.close ();

}

Else {// file does not exist

Out.println ("" The following files do not exist: " strfilename);

}

%>

转载请注明原文地址:https://www.9cbs.com/read-126874.html

New Post(0)