- import java.io.*;
-
- public class Java_CH10_HW1
- {
- public static void main(String[] args)
- {
- // TODO 自動產生的方法 Stub
- String filepath = "C:\\Users\\Dragonyue\\Desktop\\第 十章作業參考文件\\filewriterdemo1.txt";
- try
- {
- InputStreamReader sr = new InputStreamReader(
- new FileInputStream(filepath));
- BufferedReader reader = new BufferedReader(sr);
- String str = "";
- int count = 0;
- while ((str = reader.readLine()) != null)
- {
- int total = 0;
- count++;
- System.out.println(str);
- String[] input = str.split("\t");
- for (int i = 0; i < input.length; i++)
- total += Integer.parseInt(input[i]);
- System.out.println(String.format("第%d列=%d。", count, total));
- }
- reader.close();
- sr.close();
- }
- catch (IOException e)
- {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- }
-
留言
張貼留言