1.file类
1----------------
boolean makedir 创建文件夹 048 a97 A65
boolean makedirs 创建文件夹
boolean creatfile 创建文件
boolean delete 删除文件 删除的文件不能包含其他文件
boolean renameTo(File dest) 相同路径是复制 不同路径是改名+剪切
-----------1
1----------------2
boolean makedir 创建文件夹 048 a97 A653
boolean makedirs 创建文件夹4
boolean creatfile 创建文件5
boolean delete 删除文件 删除的文件不能包含其他文件6
boolean renameTo(File dest) 相同路径是复制 不同路径是改名+剪切7
-----------2.fie类判断功能:
System.out.println("exists:"+file.exists());//是否存在
System.out.println("isDirectory:"+file.isDirectory());//是否是目录
System.out.println("isHidden:"+file.isHidden());//是否隐藏
System.out.println("isCanWrite:"+file.canWrite());//是否能写
System.out.println("isCanRead:"+file.canRead());//是否能读5
1
System.out.println("exists:"+file.exists());//是否存在2
System.out.println("isDirectory:"+file.isDirectory());//是否是目录3
System.out.println("isHidden:"+file.isHidden());//是否隐藏4
System.out.println("isCanWrite:"+file.canWrite());//是否能写5
System.out.println("isCanRead:"+file.canRead());//是否能读------------------------------------
3.file类的获取功能:
*getAbsolutePath()() 获取绝对路径
* getPath() 获取x相对路径
* getName()获取名字
* long length()获取文件大小 用毫秒来表示
* Date date = new Date(file.lastModified());
SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yy-MM-dd HH:mm:ss");
String str=simpleDateFormat.format(date);
System.out.println(str);
file类的高级获取功能
File file = new File("mljqqh");
//匿名内部类
File[] files = file.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".jpg");
}
});
for (File file1 : files) {
System.out.println(file1.getAbsolutePath());
}
//lambda方式
File[] files = file.listFiles(pathname -> pathname.isFile() && pathname.getName().endsWith(".jpg"));
for (File file1 : files) {
System.out.println(file1.getAbsolutePath());
}
}
}
31
1
*getAbsolutePath()() 获取绝对路径2
* getPath() 获取x相对路径3
* getName()获取名字4
* long length()获取文件大小 用毫秒来表示5
* Date date = new Date(file.lastModified());6
SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yy-MM-dd HH:mm:ss");7
String str=simpleDateFormat.format(date);8
System.out.println(str);9
file类的高级获取功能10
File file = new File("mljqqh");11
//匿名内部类12
File[] files = file.listFiles(new FileFilter() {13
14
public boolean accept(File pathname) {15
return pathname.isFile() && pathname.getName().endsWith(".jpg");16
}17
});18
for (File file1 : files) {19
System.out.println(file1.getAbsolutePath());20
}21
//lambda方式22
File[] files = file.listFiles(pathname -> pathname.isFile() && pathname.getName().endsWith(".jpg"));23
for (File file1 : files) {24
System.out.println(file1.getAbsolutePath());25
}26
27
}28
}29
30
31
4.io类
1
windows 换行
linux换行
mac换行
追加使用的是构造方法
2
fileInputStream类
终极版本读文件
int i=0;
while ((i=fis.read())!=-1){
System.out.print((char)i);
}6
1
fileInputStream类2
终极版本读文件3
int i=0;4
while ((i=fis.read())!=-1){5
System.out.print((char)i);6
}3
万能的字节流复制文本文件
FileInputStream fis= new FileInputStream("mljqqh.txt");
FileOutputStream fos= new FileOutputStream("mljqqh1.txt");
int by=0;
while ((by=fis.read())!=-1){
fos.write(by);
}
fis.close();
fos.close();
12
1
FileInputStream fis= new FileInputStream("mljqqh.txt");2
FileOutputStream fos= new FileOutputStream("mljqqh1.txt");3
int by=0;4
while ((by=fis.read())!=-1){5
fos.write(by);6
}7
fis.close();8
fos.close();9
10
11
12
4 read(byte [])使用
FileInputStream fis= new FileInputStream("mljqqh.txt");
byte [] bys= new byte[1024];
int len;
while ((len=fis.read(bys))!=-1){
System.out.print(new String(bys,0,len));5
1
FileInputStream fis= new FileInputStream("mljqqh.txt");2
byte [] bys= new byte[1024];3
int len;4
while ((len=fis.read(bys))!=-1){5
System.out.print(new String(bys,0,len));5 read(byte [])复制文件
FileOutputStream fos = new FileOutputStream("mljqqh1.txt");
FileInputStream fis = new FileInputStream("mljqqh.txt");
byte[] bys = new byte[1024];
int len=0;
while ((len=fis.read(bys))!=-1){
fos.write(bys,0,len);
}
fis.close();
fos.close();
12
1
FileOutputStream fos = new FileOutputStream("mljqqh1.txt");2
FileInputStream fis = new FileInputStream("mljqqh.txt");3
byte[] bys = new byte[1024];4
int len=0;5
while ((len=fis.read(bys))!=-1){6
fos.write(bys,0,len);7
}8
fis.close();9
fos.close();10
11
12
6
//BufferedInputStream 读文件 BufferedInputStream是FileInputStream的 依靠 FileInputStream来装饰 左父右子2
BufferedInputStream bis= new BufferedInputStream(new FileInputStream("mljqqh.txt"));
//第一种方式
// int b=0;
// while ((b=bis.read())!=-1){
// System.out.print((char)b);
// }
//第二种方式
byte[] bys = new byte[1024];
int len=0;
while ((len=bis.read(bys))!=-1){
System.out.println(new String(bys,0,len));
}
bis.close();
18
1
//BufferedInputStream 读文件 BufferedInputStream是FileInputStream的 依靠 FileInputStream来装饰 左父右子2 2
BufferedInputStream bis= new BufferedInputStream(new FileInputStream("mljqqh.txt"));3
//第一种方式4
// int b=0;5
// while ((b=bis.read())!=-1){6
// System.out.print((char)b);7
// }8
//第二种方式9
byte[] bys = new byte[1024];10
int len=0;11
while ((len=bis.read(bys))!=-1){12
System.out.println(new String(bys,0,len));13
}14
15
16
17
bis.close();18
------------------------------------
7
/*
转化流
OutputStreamWriter构造方法
OutputStreamWriter(OutputStream out)
OutputStreamWriter(OutputStream out,string charsetName)
//字符流五种写数据的方法
public write(int ch)//写一个字符 可以写数字 java会自动装换
public write(char[] cha)写一个字符数组
public write(char[] cha,int off,int len)写一个字符数组的一部分
public write(String str)写一个字符串
public write(String str,int off,int len)写一个字符串的一部分
14
1
/*2
转化流3
OutputStreamWriter构造方法4
OutputStreamWriter(OutputStream out)5
OutputStreamWriter(OutputStream out,string charsetName)6
//字符流五种写数据的方法7
8
public write(int ch)//写一个字符 可以写数字 java会自动装换9
public write(char[] cha)写一个字符数组10
public write(char[] cha,int off,int len)写一个字符数组的一部分11
public write(String str)写一个字符串12
public write(String str,int off,int len)写一个字符串的一部分13
14
*/
------------------------------------
8
Object 类
Class getClass 返回Class类 Class.name
Tostring 直接输出对象名称就是调用该对象的Tostring()3
1
Object 类2
Class getClass 返回Class类 Class.name3
Tostring 直接输出对象名称就是调用该对象的Tostring()------------------------------------
9.==跟eauals
==
基本类型:比较的是值
引用类型:比较的是地址
------------------------------------
eauals
Object类中比较的是对象的地址
String 类对equal进行了重新,比较的是字符串的值7
1
==2
基本类型:比较的是值3
引用类型:比较的是地址4
------------------------------------5
eauals6
Object类中比较的是对象的地址7
String 类对equal进行了重新,比较的是字符串的值10.clone浅克隆
/*
Cloneable是一个标记接口
被克隆的对象需要继承这个接口
Student stu=new Student("林青霞",28);
System.out.println("stu的名字:" + stu.getName());
Object obj=stu.clone();
if (obj instanceof Student){
Student stu1=(Student)obj;
stu1.setName("周星驰");
System.out.println("stu的名字:" + stu1.getName());
}
*/
x
1
Cloneable是一个标记接口2
被克隆的对象需要继承这个接口3
Student stu=new Student("林青霞",28);4
System.out.println("stu的名字:" + stu.getName());5
Object obj=stu.clone();6
if (obj instanceof Student){7
Student stu1=(Student)obj;8
stu1.setName("周星驰");9
System.out.println("stu的名字:" + stu1.getName());10
11
12
13
}14
15
*/16
17
18
11.常量字符串相加
常量字符串相加,先看常量池里面有没有相同的字符串,有的话就返回常量地址,没有就创建·
12.string类
判断功能
boolean contains();判断大字符串是否包含小字符串
String substing (int start ,int end)包左不包右
13字符串的装换功能
byte[] gteByte() //把字符串装换成字节数组
char[] toCharArray()把字符串装换成字符数组
static String valueOf(char{} chr)//把字符数组装换成字符串
//static String valueOf(int i) 把int装换成字符串
14String的其他功能
/*
替换功能
String replace(char old,char new)
String replace(String old,String new)
去除字符串两端空格
String trim()
按照字典比较两个字符串
int compareto()
int compareToIgnoreCase()
分割功能 Sring[] split 如果分割的字符串出现在首位,那么分割的数组【0】是""
.前面加上\进行转义
String作为参数传递 跟基本类型一个效果
*/
25
1
判断功能2
boolean contains();判断大字符串是否包含小字符串3
String substing (int start ,int end)包左不包右4
13字符串的装换功能5
byte[] gteByte() //把字符串装换成字节数组6
char[] toCharArray()把字符串装换成字符数组7
static String valueOf(char{} chr)//把字符数组装换成字符串8
//static String valueOf(int i) 把int装换成字符串9
14String的其他功能10
/*11
替换功能12
String replace(char old,char new)13
String replace(String old,String new)14
去除字符串两端空格15
String trim()16
按照字典比较两个字符串17
int compareto()18
int compareToIgnoreCase()19
分割功能 Sring[] split 如果分割的字符串出现在首位,那么分割的数组【0】是"" 20
.前面加上\进行转义21
String作为参数传递 跟基本类型一个效果22
23
24
*/25
15. Random
Random 右边-左边)左边
16.泛型的定义
泛型指的是任何引用类型
17.集合
https://blog.csdn.net/qq_37025445/article/details/76563133
集合功能的概述:
a.添加功能
boolean add(E e)
boolean addAll(Collection e )//添加一个集合
b删除功能
void clear()//删除所用功能
c判断功能
boolean contains(E e)
boolean contains( Collection e )
remove(E e)
removeAll(Collection e)移除一个集合
boolean isEmpty()//判断集合是否是空
d获取功能`
iteractor//集合的专用遍历方式 两个方法 hasnext() next(0
e长度功能
size()
f交集功能
boolean retainAll(Colletion e)//两个集合的交集 A对B做交集 ,结果保存在a中 b不变 返回的是a是否发生过变化
g转换功能
Object toArrary()21
1
https://blog.csdn.net/qq_37025445/article/details/765631332
集合功能的概述:3
a.添加功能4
boolean add(E e)5
boolean addAll(Collection e )//添加一个集合6
b删除功能7
void clear()//删除所用功能8
c判断功能9
boolean contains(E e)10
boolean contains( Collection e )11
remove(E e)12
removeAll(Collection e)移除一个集合13
boolean isEmpty()//判断集合是否是空14
d获取功能`15
iteractor//集合的专用遍历方式 两个方法 hasnext() next(016
e长度功能17
size()18
f交集功能19
boolean retainAll(Colletion e)//两个集合的交集 A对B做交集 ,结果保存在a中 b不变 返回的是a是否发生过变化20
g转换功能21
Object toArrary()list的功能
增
void add(int index,Object element)//指定位置添加元素
ListIteractor List特有的迭代器
迭代器并发修改异常ConcurrentModificationException解决方法
aListIteractor 迭代修改(增删除加 )
b用for循环遍历修改(只能增加,删除会引发越界异常的)
c使用一个集合 然后操作
collecton (存取有序,有索引,数据不唯一 set跟这个刚好相反 )
ArraryList
数据结构:数组 查询快 增删满
A增
add
删
remove 返回删除的元素
改
set 返回原来的值
查
get
长度 size
LinkList 数据结构:双链表
Vector的特有功能
数据结构:数组 查询快 增删满
pubulic void addElement(E e)
public E elementAt(int index)
LinkedList的特有功能
a添加功能
public void addFirst(object o)
public void addLast(Object o)
b获取 first last
c删除first last
-------------------------------------------------
set集合特点:存储无序,数据唯一,没有索引(collection跟这个相反)
a:HashSet
数据结构是哈希表(数组+链表+红黑树)
底层hashcode()和equals(),他数据要保证唯一就要重新hashcode()和equals()
String 已经重写了hashCode 和 equals 会自动比较
-----------------------------
TreeSet
数据结构是红黑树(一种自平衡的二叉树)
排序方式:
自然排序,让类实现Comparable接口
比较器排序Comparator,使用集合构造方法,生成匿名内部类创建对象
------------------------------
LinkhashSet
数据结构:哈希表(保证唯一)+链表(存取有序)
特点:存取有序,唯一
Map就是一个顶级接口
MapSet跟collection没有关系
添加功能:
V put(V key,V value):如果没有键就添加,返回null,有键值就修改返回以前的值
删除功能:
void clear()清空
void remove()
判断:
boolean containsKey( K key)
boolean containsValue( K Value)
boolean isEmpty()
长度:size()
获取:
V get(Object key):获取值
Set<K> keySet()获取所用键
Collectio<V> values() 获取所有的键
Set<Map.Entry<K,V>,V> entrySet获取所有键值对象
iter
itco
特点:
无序
-------------
18
+=自带强转
19
StringBuffer类 线程安全,可变的字符序列。
构造方法
public StringBuffer()无参构造 初始化是16 不够再分配
pubulic StringBuffer(int capacity )指定的容量字符串缓冲区对象
pubulic StringBuffer(String str )指定字符串 内容的缓冲区对象
方法
pubulic int capacity() 返回容量
pubulic int length() 返回长度大小
技巧:使用链式编程
增append insert
删deleteCharAt(int index) delete(int start,int end) 包左不包右 delete(0,sb.length)删除全部
改:
替换 replece(int start,int end,String str ) 反转 reverse() 获取:subString返回的不是StringBuffer本身,是字符串
查
static 同一类中静态方法只能调静态方法,不能调用普通方法,因为普通成员方法依赖对象还没有创建。
20继承
this()调用空参构造
this(参数)调用实参构造方法 this("mlj",20)放在第一行
只能在本类中使用
泛型:
泛型三种:
[1]ArrayList<T> al=new ArrayList<T>();指定集合元素只能是T类型
[2]ArrayList<?> al=new ArrayList<?>();集合元素可以是任意类型,这种没有意义,一般是方法中,只是为了说明用法
[3]ArrayList<? extends E> al=new ArrayList<? extends E>();
泛型的限定:
? extends E:接收E类型或者E的子类型。
?super E:接收E类型或者E的父类型。8
1
泛型:2
泛型三种:3
[1]ArrayList<T> al=new ArrayList<T>();指定集合元素只能是T类型4
[2]ArrayList<?> al=new ArrayList<?>();集合元素可以是任意类型,这种没有意义,一般是方法中,只是为了说明用法5
[3]ArrayList<? extends E> al=new ArrayList<? extends E>();6
泛型的限定:7
? extends E:接收E类型或者E的子类型。8
?super E:接收E类型或者E的父类型。网络编程:
InetAddress获取ip
获取Class对象的三种方式
方式一:对象.getClass() 方法是 根对象Object的方法。 是其他类继承Object的getClass方法。
方式二:类名.class,你可以理解为字节码本身就是静态的,类加载的时字节码就进JVM了。所以类.class好比类调用静态方法似得调用字节码对象。
方式三:Class.forName()是Class类的静态方法。参数是字符串,字符串是类的全路径名。3
1
方式一:对象.getClass() 方法是 根对象Object的方法。 是其他类继承Object的getClass方法。 2
方式二:类名.class,你可以理解为字节码本身就是静态的,类加载的时字节码就进JVM了。所以类.class好比类调用静态方法似得调用字节码对象。3
方式三:Class.forName()是Class类的静态方法。参数是字符串,字符串是类的全路径名。