- package tools;
-
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.PipedReader;
- import java.io.PipedWriter;
- import java.io.PrintWriter;
- import java.io.Reader;
-
- public class ExIO3 {
- public static void main(String[] args) throws IOException {
- ExIO3 object1 = new ExIO3();
- object1.sortValue(object1.getValue());
- }
-
- Reader getValue () throws IOException {
- FileReader csv = new FileReader("sales.csv");
- BufferedReader in = new BufferedReader(csv);
-
- PipedWriter pipeOut = new PipedWriter();
- PipedReader pipeIn = new PipedReader(pipeOut);
- PrintWriter out = new PrintWriter(pipeOut);
-
- String line;
- String[] arrayline;
-
- //(8)読み込みソースがなくなるまで読み込み、
- // 読み込みデータをprintlnメソッドで書き込み
- while((line = in.readLine()) != null) {
- arrayline = line.split(",");
- out.println(arrayline[3]);
- out.flush();
- }
-
- in.close(); //(9)読み込みストリームのクローズ
- out.close(); //(10)書き込みストリームのクローズ
-
- return pipeIn; //(11)pipeInオブジェクトのリターン
- }
-
- void sortValue(Reader source) throws IOException {
- BufferedReader in = new BufferedReader(source);
-
- String line; String[] data = new String[5];
- int m = 0;
- int price1, price2;
-
- while ((line = in.readLine()) != null) {
- data[m] = line;
- m++;
- }
-
- //(14)売上データをソート
- for (int i = 0; i < data.length - 1; i++) {
- for (int j = data.length - 1; j > i; j--) {
- price1 = Integer.parseInt(data[j]);
- price2 = Integer.parseInt(data[j-1]);
- if (price1 > price2) {
- String temp = data[j];
- data[j] = data[j-1];
- data[j-1] = temp;
- }
- }
- }
-
- for (int k = 0; k < data.length; k++) {
- System.out.println(data[k]);
- }
- in.close(); //(16)読み込みストリームのクローズ
- }
- }