Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the read operation of jsp file operation

Shulou Source: shulou.com Published: 2022-06-02 12:30:06 09月19日 Update

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!

Tags: File content text directory article path important one line two value interest character string object boy partner form more root directory source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Shulou Tech Info Shulou Information Linux