-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferedReader_used.java
55 lines (55 loc) · 1.54 KB
/
BufferedReader_used.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.*;
class BufferedReader_used
{
public static void main(String args[]) throws IOException
{
String s = "This is a © copyright symbol " +
"but this is © not.\\n";
char buf[] = new char[s.length()];
s.getChars(0, s.length(), buf, 0);
CharArrayReader in = new CharArrayReader(buf);
BufferedReader f = new BufferedReader(in);
int c;
boolean marked = false;
while ((c = f.read()) != -1)
{
switch(c)
{
case '&':
if (!marked)
{
f.mark(32);
marked = true;
}
else
{
marked = false;
}
break;
case ';':
if (marked)
{
marked = false;
System.out.print("(c)");
}
else
System.out.print((char) c);
break;
case ' ':
if (marked)
{
marked = false;
f.reset();
System.out.print("&");
}
else
System.out.print((char) c);
break;
default:
if (!marked)
System.out.print((char) c);
break;
}
}
}
}