Java高级编程7-姜国海 流操作

java 不仅仅是编程语言

API:应用程序接口

①class File

文件:大小 名字 访问时间 创建时间 路径 
文件夹:是一个特殊的文件 大小为零 为其他文件夹提供存储信息
File(File parent, String child)
Creates a new File instance from a parent abstract pathname and a child pathname string.
Eg:
File f1 = new File("c:\\");
File f2 = new File(f1,"a.txt");
file://c:\\a.dat 
file:// 文件访问协议

操作系统中保存的时间是一个长整数,单位毫秒

绝对路径和相对路径

一般用相对路径,提高程序的可移植性

②RandomAccessFile

可以将数据直接写入硬盘,不在缓存停留

③文本流

FileInputStream file = new FileInputStream(new File("a.txt"));

Reader:
FileReader fr = new FileReader("a.txt");
int c = fr.read();
char c2 = (char)c;



FileInputStream fis = new FileInputStream("a.txt");
InputStreamReader isr = new InputStreamReader(fis,"GBK");//自定义编码格式
BufferedReader br = new BufferedReader(isr );
String s = br.readLine();
import java.io.*;
public class WriteText {
    public static void main() throws Exception{
        FileOutputStream fos = new FileOutputStream("d:\\a.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos,"GBK");

    }
}

PrintWriter类

这里写代码片

PrintStream

这里写代码片

文本流的属性(配置)config

文件后缀名.properties

property 类
继承于map,但是不能调用put 只能接受字符串类型的键值对

String getProperty(String name);

setProperty(String name);
server = www.baidu.com

Eg:

Properties p = new Properties();
p.load()


p.setProperty("server","192.168.0.0");
注册表信息

猜你喜欢

转载自blog.csdn.net/l1558198727/article/details/80980609