Guest User

Untitled

a guest
Feb 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class BytePe3 {
  5. ArrayList<Integer> numbers = new ArrayList<Integer>();
  6. int part1 = 0;
  7. int counter = 0;
  8. int sum = 0;
  9. int numberOfFiles = 0;
  10.  
  11.  
  12. public static void main(String[] args) {
  13. BytePe3 p3 = new BytePe3();
  14.  
  15. for(int n = 1; n <= 8; n++) {
  16. String xd = "integer"+n+".dat";
  17. File rawr = new File(xd);
  18. BytePe3.ReadInts i1 = p3.new ReadInts(rawr);
  19. }
  20.  
  21.  
  22. }
  23.  
  24. class ReadInts implements Runnable {
  25.  
  26. File abc;
  27.  
  28. public ReadInts(File _fileName) {
  29. abc =_fileName;
  30. }
  31.  
  32. public void run() {
  33. try {
  34. if(abc.exists() != true) {
  35. System.out.println("File doesn't exist!");
  36. } else {
  37. FileInputStream fis = new FileInputStream(abc);
  38. DataInputStream dis = new DataInputStream(fis);
  39. while(dis.available() > 0) {
  40. part1 = dis.readInt();
  41. numbers.add(part1);
  42. sum += part1;
  43. counter++;
  44. }
  45.  
  46. @SuppressWarnings("unused")
  47. int totalSize = 0;
  48.  
  49. for(int x = 0; x < numberOfFiles; x++) {
  50. totalSize = numbers.size();
  51. }
  52.  
  53. dis.close();
  54. System.out.println("Filename= "+abc+" Count = "+counter+" sum = "+sum+" In List = "+numbers.size());
  55. counter = 0;
  56. sum = 0;
  57. }
  58. } catch (Exception ex) {
  59. ex.printStackTrace();
  60. }
  61. }
  62. }
  63.  
  64. }
Add Comment
Please, Sign In to add comment