import java.io.*;
public class NumberReader {
private long minValues;
private long maxValues;
private long nValues;
private long sumOfValues;
private FileWriter fw;
private boolean isFirstOcccur = true;
private static BufferedReader brFile(String srcFile) throws FileNotFoundException{
return new BufferedReader(new FileReader(srcFile));
}
private void analysisStart() throws IOException{
fw = new FileWriter("wts\\mywork\\numbers.txt", true);
minValues = 0L;
maxValues = 0L;
nValues = 0L;
sumOfValues = 0L;
}
public static void main(String args[]) throws IOException{
String src = "a.txt";
NumberReader obj = new NumberReader();
obj.analysisStart();
BufferedReader reader = NumberReader.brFile(src);
String content = null;
while((content = reader.readLine()) != null){
obj.analyseData(content.trim());
}
obj.analysisEnd();
}
private void analyseData(String s) throws IOException{
String numbers[] = s.replaceAll("[^0-9]", " ").trim().split("\\s+");
BufferedWriter bw = new BufferedWriter(fw);
if(isFirstOcccur && numbers.length > 0){
minValues = Long.parseLong(numbers[0]);
maxValues = minValues;
isFirstOcccur = false;
}
for (int i = 0; i maxValues){
maxValues = value;
}
bw.write(numbers[i]);
bw.newLine();
bw.flush();
nValues++;
sumOfValues += value;
}
}
private void analysisEnd(){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Min is: " + minValues);
System.out.println("Max is: " + maxValues);
System.out.println("Average is: " + (sumOfValues / nValues));
System.out.println("Totale number read is: " + nValues);
}
}