Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class CSVFile0 {
  4. public static void main(String[] args) throws IOException {
  5. FileReader fr = null;
  6. StringBuilder sb = new StringBuilder();
  7. try {
  8. fr = new FileReader("CSVnumbers0.csv");
  9. int charaInt = fr.read();
  10. while(charaInt != -1) {
  11. char chara = (char) charaInt;
  12. sb.append(chara);
  13. charaInt = fr.read();
  14. }
  15. } catch(IOException ex) {
  16. System.out.println("ファイル読み込みエラーです");
  17. } finally {
  18. try {
  19. fr.close();
  20. } catch(IOException ex2) {
  21. System.out.println("ファイルクロ―ズエラーです");
  22. }
  23. }
  24. String numbers = sb.toString();
  25. System.out.println(numbers);
  26.  
  27. String[] numArray = numbers.split("[,]");
  28. int capaTotal = 0;
  29. for (int i = 0; i < numArray.length; i++) {
  30. capaTotal += Integer.parseInt(numArray[i]);
  31. }
  32. System.out.println("合計は" + capaTotal + "です");
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement