我的账户
啄木鸟学院

专注软件测试菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

JAVA_焦新瑞_20210312

[复制链接]
8487学员认证 发表于 2021-3-13 10:32:58 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
1.常用类
Math数学方法
Random  SecureRandom:随机类  安全随机类
Random ra = new Random();
SecureRandom ra1 = new SecureRandom();
Date:日期
Date date = new Date();//时间//SimpleDateFormat格式化日期  y  yyyy表示年用4数来表示
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");//时间戳   相等于北京时间1970-1-1-800时间过了多少毫秒
long time = date.getTime();//了多少毫秒
2.常用类
String:字符串相关操作
String s1 = "Hello World";//始索引 束索引 包含始不包含
s1.substring(5,8));s1.indexOf("o"));
s1.lastIndexOf("o"));//分大小的 判等
a.equalsIgnoreCase(b));
StringBuilder:连接效率低,大量的字符串连接。用StringBuilder来实现
StringBuilder/StringBuffer:变类
        者的区别
                StringBuilder线程不安全 单线程下使用   比StringBuffer效率高
                StringBuffer线程安全 多线程下使用
split join
//split(分割)  join接)String.join("分隔符")
//split" ")特殊符号时  需要转义   空格 不需要String path = "E:\\aaa\\fdd\\vv.java";
String[] temp = path.split("\\\\");//string型的数组    \\\\斜杠转义
System.out.println(String.join("/",temp));
StringJoiner:jion方法的升级版
//分隔符   前缀  
StringJoiner sj = new StringJoiner(",","hello,","!");
3.File文件、目录操作
File file = new File("C:\\Users\\Lenovo\\Desktop\\aaz.txt");
//是不是目录  (如果是本地存在的目返回true 不存在或者非目返回flase
file.isDirectory());
//是不是文件(如果是本地存在的文件 返回true 不存在或者非文件返回flase
file.isFile());//建文件 成功返回true
System.out.println("建文件的果:"+file.createNewFile());
file.isFile());//文件性 文件的最后修改时间
file.lastModified()));
//文件的绝对
file.getAbsolutePath());
//取文件名字
file.getName());//除文件
file.delete());//取目下的子目和文件 file【】
File[] fs = path.listFiles();
4.文件读写
读文件常用的类:a创建文件的对象b读文件c关闭文件
FileInputStream
FileInputStream fs = new FileInputStream(path);
int temp = fs.read();
System.out.println(temp);
while (temp != -1){
    System.out.write(temp);
    temp = fs.read();
    System.out.flush();
}
fs.close();
InputSreamReader
InputStream is = new FileInputStream(path);//
//InputStreamReader 需要一InputStream例化   InputStream抽象
InputStreamReader isr = new InputStreamReader(is);


BufferedReader
5.读写文件
写文件:a创建一个对象b调用write方法写文件c关闭对象
写文件的常用类
FileOutputStream
FileOutputStream fw = new FileOutputStream(path,true);
fw.write(content.getBytes());//stringbyte[]
fw.close();
OutputStreaWriter
Writer w = new FileWriter(path,true);
BufferedWriter bw = new BufferedWriter(w);
bw.write(content);
bw.close();
w.close();
BufferedWriter


回复

使用道具 举报

关注0

粉丝0

帖子26

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注软件测试菁英教育

客服电话:17792550360

客服时间:9:00-21:00

卓目鸟学苑 - 专注软件测试菁英教育!( 陕ICP备2025058934号-2 )

版权所有 © 西安菁英教育科技有限公司 2023-2026