1 | |
---|
2 | /* |
---|
3 | * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved. |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and distribute this software |
---|
6 | * and its documentation for NON-COMMERCIAL purposes and without |
---|
7 | * fee is hereby granted provided that this copyright notice |
---|
8 | * appears in all copies. Please refer to the file "copyright.html" |
---|
9 | * for further important copyright and licensing information. |
---|
10 | * |
---|
11 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF |
---|
12 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
---|
13 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
---|
14 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR |
---|
15 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR |
---|
16 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. |
---|
17 | */ |
---|
18 | |
---|
19 | import java.io.*; |
---|
20 | import java.util.*; |
---|
21 | |
---|
22 | public class StreamConverter { |
---|
23 | |
---|
24 | static void writeOutput(String str) { |
---|
25 | |
---|
26 | try { |
---|
27 | FileOutputStream fos = new FileOutputStream("test.txt"); |
---|
28 | Writer out = new OutputStreamWriter(fos, "UTF8"); |
---|
29 | out.write(str); |
---|
30 | out.close(); |
---|
31 | } catch (IOException e) { |
---|
32 | e.printStackTrace(); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | static String readInput() { |
---|
37 | |
---|
38 | StringBuffer buffer = new StringBuffer(); |
---|
39 | try { |
---|
40 | FileInputStream fis = new FileInputStream("test.txt"); |
---|
41 | InputStreamReader isr = new InputStreamReader(fis, "UTF8"); |
---|
42 | Reader in = new BufferedReader(isr); |
---|
43 | int ch; |
---|
44 | while ((ch = in.read()) > -1) { |
---|
45 | buffer.append((char)ch); |
---|
46 | } |
---|
47 | in.close(); |
---|
48 | return buffer.toString(); |
---|
49 | } catch (IOException e) { |
---|
50 | e.printStackTrace(); |
---|
51 | return null; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | public static void main(String[] args) { |
---|
56 | |
---|
57 | String jaString = |
---|
58 | new String("\u65e5\u672c\u8a9e\u6587\u5b57\u5217"); |
---|
59 | |
---|
60 | writeOutput(jaString); |
---|
61 | String inputString = readInput(); |
---|
62 | String displayString = jaString + " " + inputString; |
---|
63 | new ShowString(displayString, "Conversion Demo"); |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|
67 | |
---|