import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class FileReaderDemo {
private static void readFile() {
File file = new File("E:\\JavaTest\\FileTest\\file.txt");
try {
BufferedReader bReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
String line = null;
String[] lineContext = new String[2];
String[] contexts = new String[7];
for (int i = 0; (line = bReader.readLine()) != null; i++) {
lineContext = line.split("=");
contexts[i] = lineContext[1];
System.out.println(contexts[i]);
}
bReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
readFile();
}
}
Java-读文件
最新推荐文章于 2024-04-03 15:11:06 发布