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 does java find lines with the same fields in two text files

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how java finds lines with the same fields in two text files". In daily operations, I believe many people have doubts about how java finds lines with the same fields in two text files. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "how to find out the lines with the same fields in two text files". Next, please follow the editor to study!

Is there any convenient class library for file comparison in Java? For example: files Old.txt and New.txt, the first line is the column name, you need to take out the same content of the Name field in the file. Some of the data are as follows:

Old.txt

New.txt

Name Dept

Rachel Sales

Ashley rotated D

Matthew Sales

Alexis Sales

Megan Marketing

Name Dept

Emily HR

Ashley rotated D

Matthew Sales

Alexis Sales

Megan Marketing

The expected results are as follows:

Java is not an aggregate language, it requires a lot of loops and judgments, it will be long to write, and the code should look something like this:

...

While ((String lineText = comparedReader.readLine ())! = null) {

String comparedLine = lineText.trim ()

If (searchText.equals (comparedLine)) {

LineStr = "# = Equal:" + lineNum + "= # #\ n"

Break

}

LineNum++

}

Rbw.write (lineStr)

ComparedReader.reset ()

...

In terms of text comparison, it is much easier to use the aggregator SPL. A set of function libraries in the field of set operations are carefully designed to implement the same process code more succinctly, such as the above question, only 2 lines:

A

one

= Old=file ("Old.txt") .import@t (), New=file ("New.txt") .import@t ()

two

= Old. (Name) ^ New. (Name)

At this point, the study on "how java finds lines with the same fields in two text files" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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