Statistic Data from File Via Java

xiaoxiao2021-04-11  2.1K+

Due to the needs of a friend, there is a need to count the data in many files. Since the workload of manual statistics is relatively large, he will help me to count. Demand: Mriage of all data from small to big into a file, repeat data only! And statistics on the top four of the same data!

Data fragment:

19610618, 19610619, 19610622, 19610623, 19610718, 19980814, 19980820, 19980822, 19980831,

2004084, 20040809, 20040810, 20050405, 20050429, 20050619,

Data is dispersed in different files

/ ** * @Author Seave * @since 2006-06-25 * @Version 1.0 * File Data Statistics * Put all data from small to big merge into a file, repeat data only keep one! * Statard the number of the top four identical data, respectively! * / Import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.util.ArrayList;

Import java.io.ioException;

Public class DataStatic {// Original Data File Directory Private Final Static String DirectoryPath = "D: // CHENGQIAO / /"; // Statistics Generated File Private Final Static String GenetratePath = "D: //statisticResult.txt"; / ** * @Author Seave * @since 2006-06-25 * Read file * @Return * / private static arraylist readfile () {arraylist al = new arraylist (); file file = new file (directoryPath); string filelist [] = file.list (); for (int i = 0; i 0) {String Mindata = (string) Al.Get (0); int Tempindex = 0;

IF (alsort.contains (minData)) {// If this data is already sorted, then this data is deleted, while restarting the cyclic al.remove (Mindata); Continue;} for (int J = 0; j 0) {// Current data compared with the data in the cloning array, MINDATA = Tempdata; Tempindex = J }} // system.out.println ("Mindata Result =" MINDATA); // system.out.println ("===================== ============ "); Alsort.Add (Mindata); // When the minimum data is obtained, the minimum data obtained by the loop is removed from the cloning array alclone.remove (Tempindex);} return Alsort;} / ** * @Author Seave * @since 2005-06-25 * Count the first four of the top four of the same data * * / private static arraylist statisticData () {arraylist fumbal = new arraylist (); arraylist fourandcountal = New arraylist (); arraylist al = sortdata (); for (int i = 0; i

Since 2005-06-25 * Writing Document * / Private Static Void WriteFile (ArrayList Al) {Try {file f = new file (geneteratePath); if (! f.exists ()) f.createNewFile (); fileOutputStream Fout = New fileOutputStream (geneteratePath); for (int i = 0; i

1961: 66 Data 1962: 61 Data 1963: 62 Data 1964: 64

1998: 52 Data 1999: 34 Data 2000: 42 Data 2001: 42 Data 2002: 40 Data 2003: 44 Data 2004: 45 Data 2005: 48

19610618, 19610619, 19610622, 19610623,

20040827, 20041215, 20050310, 20050311,

转载请注明原文地址:https://www.9cbs.com/read-133587.html

New Post(0)