Test.java
1.32 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
test1();
}
public static void test1(){
String param="1225sddfh";
System.out.println(param.substring(0,1));
int s=param.length();
System.out.println(s);
}
public static void reader() throws IOException{
File fileName=new File("D:\\test.txt");
try {
fileName.createNewFile();
BufferedWriter bWriter=new BufferedWriter(new FileWriter(fileName));
bWriter.write("哈哈哈哈");
bWriter.flush();
bWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStreamReader reader = new InputStreamReader(
new FileInputStream(fileName)); // 建立一个输入流对象reader
BufferedReader br = new BufferedReader(reader); // 建立一个对象,它把文件内容转成计算机能读懂的语言
String line = "";
line = br.readLine();
while (line != null) {
line = br.readLine(); // 一次读入一行数据
}
System.out.println(line);
}
}