In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the jsp file operation how to achieve read operation, the article introduces in great detail, has a certain reference value, interested friends must read it!
File manipulation is one of the important contents of website programming. Asp has discussed a lot about file manipulation. Let's take a look at how it is implemented in jsp.
Two files are used here, one jsp file and one javabean file. You can easily read the text file by calling javabean in jsp. Please place a text file afile.txt to the test directory of the web root directory, and after the javabean file is compiled, put the class file in the corresponding class directory (tomcat environment).
Read.jsp
Contents of the file:
Line 1:
Undefined
/ / DelimitedDataFile.java bean file source code
/ / Import java package
Import java.io.*
Import java.util.StringTokenizer
Public class DelimitedDataFile
{
Private String currentRecord = null
Private BufferedReader file
Private String path
Private StringTokenizer token
/ / create a file object
Public DelimitedDataFile ()
{
File = new BufferedReader (new InputStreamReader (System.in), 1)
}
Public DelimitedDataFile (String filePath) throws FileNotFoundException
{
Path = filePath
File = new BufferedReader (new FileReader (path))
}
/ / set the file path
Public void setPath (String filePath)
{
Path = filePath
Try {
File = new BufferedReader (new
FileReader (path))
} catch (FileNotFoundException e) {
System.out.println ("file not found")
}
}
/ / get the file path
Public String getPath () {
Return path
}
/ / close the file
Public void fileClose () throws IOException
{
File.close ()
}
/ / read the next row of records, and return-1 if not
Public int nextRecord ()
{
Int returnInt =-1
Try
{
CurrentRecord = file.readLine ()
}
Catch (IOException e)
{
System.out.println ("readLine problem, terminating.")
}
If (currentRecord = = null)
ReturnInt =-1
Else
{
Token = new StringTokenizer (currentRecord)
ReturnInt = token.countTokens ()
}
Return returnInt
}
/ / returns the entire record as a string
Public String returnRecord ()
{
Return currentRecord
}
}
The above is all the contents of the article "how to read jsp File Operation". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.