Variable declaration
Java.lang.String strFileName; Filename
Java.io.File objfile; File objects
Java.io.FileReader Objfilereader; Read File objects
char[] Chrbuffer = new CHAR[10]; Buffer
int intlength; The number of characters actually read (one character in Chinese)
Set the file name to read
strFileName = "D:\\test.txt";
Create a File object
objfile = new Java.io.File (strFileName);
To determine whether a file exists
if (objfile.exists ()) {//File exists
Create a read file object
Objfilereader = new Java.io.FileReader (objfile);
Read the contents of the file
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 file does not exist:" +strfilename);
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service