缓冲字符流
缓冲字符输出流
package com.mobiletrain;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
public class BufferedWritePractice {
public static void main(String[] args) {
try {
Writer writer = new FileWriter("E:\\data\\1000phone\\test\\bufferedwrite.txt");
BufferedWriter bw = new BufferedWriter(writer);
bw.write("1da3546fsd");
bw.close();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("200,OK");
}
}
缓冲字符输出流
package com.mobiletrain;
import java.io.*;
public class BufferedReaderPractice {
public static void main(String[] args) {
try {
Reader reader = new FileReader("E:\\data\\1000phone\\test\\bufferedwrite.txt");
BufferedReader br = new BufferedReader(reader);
String line=br.readLine();
System.out.println(line);
br.close();
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
File类
package com.mobiletrain.file;
import java.io.File;
import java.io.FileFilter;
public class FileFilterPractice {
public static void main(String[] args) {
File path = new File("E:\\data\\1000phone\\img");
System.out.println(path.isDirectory());
System.out.println(path.isFile());
FileFilter fileFilter = new FileFilter(){
@Override
public boolean accept(File pathname) {
boolean result = pathname.isFile();
return result;
}
};
File[] files = path.listFiles(fileFilter);
for (File file :
files) {
System.out.println(file.getName());
}
}
}
Properties对象
-
load(输入流)
加载输入流里面的配置,一般为properties文件
格式为key=value[换行]
package com.mobiletrain.properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesPractice {
public static void main(String[] args) {
try {
InputStream is = new FileInputStream("E:\\data\\1000phone\\test\\user.properties");
Properties properties = new Properties();
properties.load(is);
String username=properties.getProperty("user");
String password = properties.getProperty("password");
String gender = properties.getProperty("gender","unknow");
String mobile = properties.getProperty("mobile","unknow");
System.out.println(username);
System.out.println(password);
System.out.println(gender);
System.out.println(mobile);
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
网络编程
概述
网络协议
需要守护的“游戏规则”
方法
|