Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use BufferedReader to read numeric values in TXT files and output maximum values

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to use BufferedReader to read values in TXT files and output the maximum value", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use BufferedReader to read values in TXT files and output the maximum value.

BufferedReader reads the maximum value of 1. 0 in the TXT file. Title

Read the numbers in the txt file and output the maximum

Output maximum value 92

2.BufferedReader introduction

BufferedReader is a buffered character input stream. It inherits from Reader.

The purpose of BufferedReader is to add some buffering to other character input streams.

List of BufferedReader functions:

BufferedReader (Reader in) BufferedReader (Reader in, int size) void close () void mark (int markLimit) boolean markSupported () int read () int read (char [] buffer, int offset, int length) String readLine () boolean ready () void reset () long skip (long charCount) 3. Train of thought

Open a file

Use BufferedReader to read

ReadLine reads each line and saves it to a new String variable

Convert the numbers in String into an array

Compare the maximum value from the array

4. problem

The readLine () method of BufferedReader is blocking. If it reaches the end of the stream, it returns null, but if the socket of client is destroyed after it is closed, it will generate an IO exception. Remember to close after use.

Use readLine to read each line in turn, and output after processing. If you use the following method, the first character of the line except the first line will be lost because of the judgment condition of br.read ()! =-1. Because it has already read one character when executing this condition, but there is no processing for this character here, so there will be one character missing if you write while (br.readLine ()) here! = null) there will be another line missing one line!

String str = null;br=new BufferedReader (new FileReader (fileName)); while (br.read ()! =-1) {str = buf.readLine ();}

Java.lang.NumberFormatException: For input string: "" Integer.valueOf (S2 [I]) here; the beginning and end of the parameter cannot contain spaces

For (int iTuno Bandi)

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report