-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInformationOperation.java
More file actions
122 lines (111 loc) · 3.4 KB
/
Copy pathInformationOperation.java
File metadata and controls
122 lines (111 loc) · 3.4 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package realcode;
import java.io.*;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class InformationOperation {
int n;
@SuppressWarnings("null")
public StringBuffer operationFile(String studentInformation,String longer) {
StringBuffer l=new StringBuffer(studentInformation);
String s;
int j=l.length();
char[] a;
for(int i = 0;i<longer.length();i=i+7) {
a=new char[7];
try {
longer.getChars(i, i+7, a, 0);
} catch( Exception ex) {
System.out.println("触发异常...");
}
s = String.valueOf(a);
if(l!=null)
l.append(s);
if ((i + 7) % 7 == 0 && (i + 7) % 14 != 0) {
l.append(",");
j++;
}
else if((i + 7) % 14 == 0) {
l.append("。\n");
j=j+2;
}
j=j+7;
}
l.deleteCharAt(j-1);
return l;
}
public String readFile() {
String original = null;
int n=-1;
char[] a = new char[100];//缓存,
try {
File file = new File("e:\\B.txt");
InputStream fli = new FileInputStream(file);
InputStreamReader in = new InputStreamReader(fli, "GBK");
while((n=in.read(a,0,100))!=-1) {
String s = new String(a,0,n);
this.n=n;
if(original!=null)
original = original+s;
else original=s;
}
in.close();
}
catch (IOException e) {
System.out.println("File read erroe:"+e);
}
return original;
}
public boolean outFile(String a) {
byte [] b = a.getBytes();
try {
File file = new File("e:\\A.txt");
OutputStream out = new FileOutputStream(file,true);
out.write(b);
out.flush();
out.close();
}
catch (IOException e) {
System.out.println("File read erroe:"+e);
}
return true;
}
public void FindSth(String Str){
int m = 0;
StringBuffer s1=new StringBuffer(Str);
a:
while (true) {
System.out.println("请输入序号:\n1:查询词句\n2:退出程序\n");
try {
Scanner reader0 = new Scanner(System.in);
m = reader0.nextInt();
}
catch(Exception e) {
System.out.println("文本中没有该字符!");
}
switch (m) {
case 1:
System.out.println("输入你想要查询的字或词:\n");
Scanner reader1 = new Scanner(System.in);
String s2 = reader1.nextLine();
Pattern pattern = Pattern.compile(s2);
Matcher matcher = pattern.matcher(s1);
if (matcher.find()) {
int num = 1;
while (matcher.find()) {
num++;
}
System.out.println("“"+s2+"”出现的次数为:" + num);
} else {
System.out.println("文本中没有该字符");
}
break;
case 2:
System.out.println("本次实验结束!");
break a;
default:
System.out.println("您输入的编号有误,请重新输入");
}
}
}
}