public static void main(String[] args) {
//System 类 的 public final static InputStream in = null;
// System.in 编译类型 InputStream
// System.in 运行类型 BufferedInputStream
// 表示的是标准输入 键盘
System.out.println(System.in.getClass()); //老韩解读
//1. System.out public final static PrintStream out = null;
//2. 编译类型 PrintStream
//3. 运行类型 PrintStream
//4. 表示标准输出 显示器
System.out.println(System.out.getClass()); System.out.println("hello, 韩顺平教育~"); Scanner scanner = new Scanner(System.in);
System.out.println("输入内容");
String next = scanner.next();
System.out.println("next=" + next); }

字节打印流(本质还是输出流)

    public static void main(String[] args) throws IOException {

        PrintStream out = System.out;
//在默认情况下,PrintStream 输出数据的位置是 标准输出,即显示器
/*
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
} */
out.print("john, hello");
//因为print底层使用的是write , 所以我们可以直接调用write进行打印/输出
out.write("韩顺平,你好".getBytes());
out.close(); //我们可以去修改打印流输出的位置/设备
//1. 输出修改成到 "e:\\f1.txt"
//2. "hello, 韩顺平教育~" 就会输出到 e:\f1.txt
//3. public static void setOut(PrintStream out) {
// checkIO();
// setOut0(out); // native 方法,修改了out
// }
System.setOut(new PrintStream("e:\\f1.txt"));
System.out.println("hello, 韩顺平教育~"); }

字符打印流

    public static void main(String[] args) throws IOException {

        //PrintWriter printWriter = new PrintWriter(System.out);
PrintWriter printWriter = new PrintWriter(new FileWriter("e:\\f2.txt"));
printWriter.print("hi, 北京你好~~~~");
printWriter.close();//flush + 关闭流, 才会将数据写入到文件.. }

配置文件,Properties类    格式:  ip=225.225.225.225   name=tom

读取

    public static void main(String[] args) throws IOException {
//使用Properties 类来读取mysql.properties 文件 //1. 创建Properties 对象
Properties properties = new Properties();
//2. 加载指定配置文件
properties.load(new FileReader("src\\mysql.properties"));
//3. 把k-v显示控制台
properties.list(System.out);
//4. 根据key 获取对应的值
String user = properties.getProperty("user");
String pwd = properties.getProperty("pwd");
System.out.println("用户名=" + user);
System.out.println("密码是=" + pwd); }

写入&修改

    public static void main(String[] args) throws IOException {
//使用Properties 类来创建 配置文件, 修改配置文件内容 Properties properties = new Properties();
//创建
//1.如果该文件没有key 就是创建
//2.如果该文件有key ,就是修改
/*
Properties 父类是 Hashtable , 底层就是Hashtable 核心方法
public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
} // Makes sure the key is not already in the hashtable.
Entry<?,?> tab[] = table;
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;
@SuppressWarnings("unchecked")
Entry<K,V> entry = (Entry<K,V>)tab[index];
for(; entry != null ; entry = entry.next) {
if ((entry.hash == hash) && entry.key.equals(key)) {
V old = entry.value;
entry.value = value;//如果key 存在,就替换
return old;
}
} addEntry(hash, key, value, index);//如果是新k, 就addEntry
return null;
} */
properties.setProperty("charset", "utf8");
properties.setProperty("user", "汤姆");//注意保存时,是中文的 unicode码值
properties.setProperty("pwd", "888888"); //将k-v 存储文件中即可
properties.store(new FileOutputStream("src\\mysql2.properties"), null);
System.out.println("保存配置文件成功~"); }

最新文章

  1. vim linux下查找显示^M并且删除
  2. Leetcode # 169, 229 Majority Element I and II
  3. LoadRunner替换字符串(可以同时替换多个)
  4. 16个不错的git别名
  5. 代码实现Layout android:layout_alignParentRight
  6. SqLiter
  7. Android BaseAdapter
  8. Chrome浏览器加载CSS文件TTFB waiting超时的奇葩问题
  9. sass 安装与使用
  10. 基于Parallax设计HTML视差效果
  11. java类的种类
  12. 通过shell操作串口
  13. 串行FLASH文件系统FatFs---转自野火论坛
  14. js、jquery实现放大镜效果
  15. rsyslog的配置文件使用方法
  16. 机器学习实战(Machine Learning in Action)学习笔记————07.使用Apriori算法进行关联分析
  17. week4
  18. 最小化安装k8s
  19. VTK中的装配体(vtkAssembly)
  20. MAC上安装GCC失败

热门文章

  1. Gradle 使用@Value注册编译报错
  2. Java语言的特点有哪些?
  3. Linux如何查看某个端口是否被占用
  4. AOP——基于AspectJ的注解来实现AOP操作
  5. 洋桃电子之STM32
  6. PC端操作系统、移动端操作系统、嵌入式操作系统
  7. 【静态页面架构】CSS之链接和图像
  8. mysql 合并查询结果
  9. JavaScript操作select下拉框选项移动
  10. Servlet学习记录