Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ce7a76

Browse files
committed
Java第二十二天
1 parentcc86c74 commit9ce7a76

File tree

68 files changed

+1515
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1515
-0
lines changed

‎day22/code/day22_IO/.classpath‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentrykind="src"path="src"/>
4+
<classpathentrykind="con"path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentrykind="output"path="bin"/>
6+
</classpath>

‎day22/code/day22_IO/.project‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>day22_IO</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding//src/cn/itcast_12/JDK7Demo.java=UTF-8
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7

‎day22/code/day22_IO/a.txt‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cn.itcast_01;
2+
3+
import java.io.IOException;
4+
import java.io.Reader;
5+
6+
public class MyBufferedReader {
7+
private Reader r;
8+
9+
public MyBufferedReader(Reader r) { // Reader r = new FileReader("my.txt");
10+
this.r = r;
11+
}
12+
13+
public String readLine() throws IOException {
14+
/*
15+
* ����������֪����r����r�����ȡ���������ַ�ʽ��һ�ζ�ȡһ���ַ���һ�ζ�ȡһ���ַ�����
16+
* ����׼�����ĸ���?���������ķ�ʽ�����Ȳ���ȷ�������ԣ�����ȷ��һ�ζ�ȡһ���ַ���
17+
* ����ÿ�ζ�ȡһ���ַ�������ȡ�ڶ����ַ���ʱ��ǰһ���ͻᶪʧ�����ԣ�����Ҫ��취�Ѷ�ȡ�����ַ�����������
18+
* ��ʲô��?ͨ���򵥵ķ�������������ȷ����StringBuilder
19+
*/
20+
StringBuilder sb = new StringBuilder();
21+
22+
// while (true) {
23+
// // һ�ζ�ȡһ���ַ�
24+
// int ch = r.read();
25+
// if (ch == '\r') {
26+
// continue;
27+
// }
28+
// if (ch == '\n') {
29+
// // return sb.toString();
30+
// break;
31+
// } else {
32+
// sb.append((char) ch);
33+
// }
34+
// }
35+
// return sb.toString();
36+
37+
// ��ν����ѭ��������?
38+
39+
int ch = 0;
40+
while ((ch = r.read()) != -1) {
41+
if (ch == '\r') {
42+
continue;
43+
}
44+
if (ch == '\n') {
45+
return sb.toString();
46+
} else {
47+
sb.append((char) ch);
48+
}
49+
}
50+
51+
// ��ֹ���ݶ�ʧ
52+
if (sb.length() > 0) {
53+
return sb.toString();
54+
}
55+
56+
return null;
57+
58+
}
59+
60+
public void close() throws IOException {
61+
r.close();
62+
}
63+
}

‎day22/code/day22_IO/array.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello
2+
world
3+
java

‎day22/code/day22_IO/b.txt‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cn.itcast_01;
2+
3+
import java.io.IOException;
4+
import java.io.Reader;
5+
6+
public class MyBufferedReader {
7+
private Reader r;
8+
9+
public MyBufferedReader(Reader r) { // Reader r = new FileReader("my.txt");
10+
this.r = r;
11+
}
12+
13+
public String readLine() throws IOException {
14+
/*
15+
* ����������֪����r����r�����ȡ���������ַ�ʽ��һ�ζ�ȡһ���ַ���һ�ζ�ȡһ���ַ�����
16+
* ����׼�����ĸ���?���������ķ�ʽ�����Ȳ���ȷ�������ԣ�����ȷ��һ�ζ�ȡһ���ַ���
17+
* ����ÿ�ζ�ȡһ���ַ�������ȡ�ڶ����ַ���ʱ��ǰһ���ͻᶪʧ�����ԣ�����Ҫ��취�Ѷ�ȡ�����ַ�����������
18+
* ��ʲô��?ͨ���򵥵ķ�������������ȷ����StringBuilder
19+
*/
20+
StringBuilder sb = new StringBuilder();
21+
22+
// while (true) {
23+
// // һ�ζ�ȡһ���ַ�
24+
// int ch = r.read();
25+
// if (ch == '\r') {
26+
// continue;
27+
// }
28+
// if (ch == '\n') {
29+
// // return sb.toString();
30+
// break;
31+
// } else {
32+
// sb.append((char) ch);
33+
// }
34+
// }
35+
// return sb.toString();
36+
37+
// ��ν����ѭ��������?
38+
39+
int ch = 0;
40+
while ((ch = r.read()) != -1) {
41+
if (ch == '\r') {
42+
continue;
43+
}
44+
if (ch == '\n') {
45+
return sb.toString();
46+
} else {
47+
sb.append((char) ch);
48+
}
49+
}
50+
51+
// ��ֹ���ݶ�ʧ
52+
if (sb.length() > 0) {
53+
return sb.toString();
54+
}
55+
56+
return null;
57+
58+
}
59+
60+
public void close() throws IOException {
61+
r.close();
62+
}
63+
}
994 Bytes
Binary file not shown.
993 Bytes
Binary file not shown.
1.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp