Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class CSVFile0 {
- public static void main(String[] args) throws IOException {
- FileReader fr = null;
- StringBuilder sb = new StringBuilder();
- try {
- fr = new FileReader("CSVnumbers0.csv");
- int charaInt = fr.read();
- while(charaInt != -1) {
- char chara = (char) charaInt;
- sb.append(chara);
- charaInt = fr.read();
- }
- } catch(IOException ex) {
- System.out.println("ファイル読み込みエラーです");
- } finally {
- try {
- fr.close();
- } catch(IOException ex2) {
- System.out.println("ファイルクロ―ズエラーです");
- }
- }
- String numbers = sb.toString();
- System.out.println(numbers);
- String[] numArray = numbers.split("[,]");
- int capaTotal = 0;
- for (int i = 0; i < numArray.length; i++) {
- capaTotal += Integer.parseInt(numArray[i]);
- }
- System.out.println("合計は" + capaTotal + "です");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement