Yurttas/PL/OOL/Java/F/06/01/01/SortAscString00.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 2003
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : September 1, 2003.
11 * @author : Salih Yurttas.
12 */
13
14
15import java.util.*;
16import java.io.*;
17
18public class SortAscString00 {
19
20 public static void main(String[] args)
21 throws IOException
22 {
23 List data = getData();
24
25 Collections.sort(data);
26
27 printSortedData(data);
28 }
29
30 public static List getData()
31 throws IOException
32 {
33 DataInputStream dIS = new DataInputStream(System.in);
34 Reader kR = new BufferedReader(new InputStreamReader(dIS));
35 StreamTokenizer kTokens = new StreamTokenizer(kR);
36
37 System.out.println();
38 System.out.print("-> inFileName : ");
39 System.out.flush();
40 kTokens.nextToken();
41 String inFileName = kTokens.sval;
42
43 FileInputStream fInS = new FileInputStream(inFileName);
44 Reader fR = new BufferedReader(new InputStreamReader(fInS));
45 StreamTokenizer fTokens = new StreamTokenizer(fR);
46
47 List list = new ArrayList();
48 while(fTokens.nextToken() != fTokens.TT_EOF)
49 list.add(fTokens.sval);
50
51 fR.close();
52
53 return list;
54 }
55
56 public static void printSortedData(final List list)
57 throws IOException
58 {
59 DataInputStream dIS = new DataInputStream(System.in);
60 Reader kR = new BufferedReader(new InputStreamReader(dIS));
61 StreamTokenizer kTokens = new StreamTokenizer(kR);
62
63 System.out.println();
64 System.out.print("-> outFileName : ");
65 System.out.flush();
66 kTokens.nextToken();
67 String outFileName = kTokens.sval;
68
69 FileOutputStream fOS = new FileOutputStream(outFileName);
70 PrintWriter pW = new PrintWriter(fOS);
71
72 int n = list.size();
73 for(int i=0; i<n; i++)
74 pW.println(list.get(i));
75
76 pW.close();
77 }
78
79}