java8_api_misc
属性文件处理
概念
加载并读取文件内容
修改文件内容
获取系统属性
该文件是一个文本文件,以properties作为其后缀,内容格式为
key1=value1
用于保存简单的配置信息,保存国际化资源
config.properties
#second
#Tue Feb 13 09:49:22 CST 2018
url=bbbb
pw=qqqqq
driver=odbc
id=fgy ============================
package java_20180213_api_misc; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties; public class PropertiesDemo { public static void main(String[] args) throws Exception {
Properties p1=new Properties();
//这个文件放在项目的根目录下,或者写明路径,才能找到
p1.load(new FileInputStream("WebContent\\config.properties"));
p1.forEach((n,v)->System.out.println(n+"="+v));
// System.out.println(p1.getProperty("id"));
p1.setProperty("pw", "qqqqq");
p1.store(new FileOutputStream("WebContent\\config.properties"), "second"); // Properties sp=System.getProperties();
// sp.forEach((n,v)->System.out.println(n+"="+v));
} }
zip格式处理
zip格式介绍
创建zip文件
解压zip文件
读取zip文件内容
相关的类
ZipEntry zip文件中的一个条目
ZipInputStream 从zip文件中读取ZipEntry
ZipOutputStream 向zip文件中写入ZipEntry
ZipFile 读取ZipEntry的工具类
完成的任务
创建zip文件
解压zip文件
读取zip文件内容
package java_20180213_api_misc; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; public class ZipDemo { public static void main(String[] args) throws Exception {
// createZip();
// unzip();
// list();
list2();
} // private static void createZip() throws Exception{
// try(ZipOutputStream zps=new ZipOutputStream(new FileOutputStream("WebContent\\txt\\aa.zip"))){
// zps.setLevel(Deflater.BEST_COMPRESSION);
// ZipEntry ze1=new ZipEntry("f2.txt");
// zps.putNextEntry(ze1);
// BufferedInputStream bis=new BufferedInputStream(new FileInputStream("WebContent\\txt\\f2.txt"));
// byte[] buffer=new byte[1024];
// int len=-1;
// while ((len=bis.read(buffer, 0, buffer.length))!=-1) {
// zps.write(buffer, 0, len);
// }
// bis.close();
//
// ZipEntry ze2=new ZipEntry("f4.txt");
// zps.putNextEntry(ze2);
// BufferedInputStream bis1=new BufferedInputStream(new FileInputStream("WebContent\\txt\\f3.txt"));
// byte[] buffer1=new byte[1024];
// int len1=-1;
// while ((len1=bis1.read(buffer1, 0, buffer1.length))!=-1) {
// zps.write(buffer1, 0, len1);
// }
// bis1.close();
// }
// }
// private static void unzip() throws Exception{
// try(ZipInputStream zis=new ZipInputStream(new FileInputStream("WebContent\\txt\\aa.zip"))){
// ZipEntry entry=null;
// while ((entry=zis.getNextEntry())!=null) {
// String name=entry.getName();
// String dir="txt"+File.separator+name;
// File file=new File(dir);
// if (!file.getParentFile().exists()) {
// file.getParentFile().mkdirs();
// }
// file.createNewFile();
// BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));
// byte[] buffer=new byte[1024];
// int len=-1;
// while ((len=zis.read(buffer, 0, buffer.length))!=-1) {
// bos.write(buffer, 0, len);;
// }
// bos.close();
// }
// }
// } // private static void list() throws Exception{
// ZipFile zf=new ZipFile("WebContent\\txt\\aa.zip");
// Enumeration<? extends ZipEntry> e=zf.entries();
// while (e.hasMoreElements()) {
// ZipEntry ze=e.nextElement();
// System.out.println(ze.getName());
// }
// }
private static void list2() throws Exception{
ZipFile zf=new ZipFile("WebContent\\txt\\aa.zip");
zf.stream().forEach(entry->System.out.println(entry.getName()));
} }
java8_api_misc的更多相关文章
随机推荐
- leetcode日记 HouseRobber I II
House Robber I You are a professional robber planning to rob houses along a street. Each house has a ...
- 将float数据类型转换为str
示例程序: #include <stdio.h> . . void UART_send_byte(char dat); void UART_send_string(unsigned cha ...
- Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...
- 深圳奥特迅现金流量——RESSET数据库
现金流不好,很多年都是负数.到公司官方网站上收集信息,拳头产品有矩阵柔性充电堆,主要盈利产品有电源和电源管理系统.还承担了深圳市的充电桩交钥匙项目. 下面是它这些年的股价,在大牛市的时候也上升至五十几 ...
- django遇到的问题-系列1
django开发中遇到的问题以及解决方法: 1.You called this URL via POST, but the URL doesn't end in a slash and you hav ...
- stand up
#version_s#1.7#version_e# #update_s#https://files.cnblogs.com/files/dyh221/update.zip#update_e#
- mysql com.mysql.cj.jdbc.Driver 配置
需配置时区 例如 url jdbc:mysql://127.0.0.1/sell?serverTimezone=Hongkong&useUnicode=true&characterEn ...
- Linux 驱动——LED(驱动分离分层)
led_dev.c文件: #include <linux/module.h>#include <linux/version.h> #include <linux/init ...
- CSS第二篇
给导航设置圆角的代码: c3 里面的属性:border-radius:7px: 1补充盒子问题 (盒子边框紧邻变粗问题)将两个盒子边框重叠并且设置定位提高层级避免盒子重叠,鼠标放上去只显示一个盒子的边 ...
- phpStudy 切换版本后没有权限的问题
在httpd-vhosts.conf配置如下: <VirtualHost *:80> ServerName www.jy.com DocumentRoot "C:\htdocs\ ...