Java实训第16天8/17

来源:互联网 发布:淘宝网刷流量 编辑:程序博客网 时间:2024/05/02 04:27
1.递归:java中的一个方在其内部调用自己
判断如何结束
public  void show(){

show();
}
2.持久化操作:数据在瞬时状态和持久状态转换的机制
瞬时数据:保存在内存中,jvm停止 数据丢失
持久数据:保存在硬盘中,jvm停止,数据依然存在
3.完成持久化操作
a)IO流:
读数据
写数据
b)jdbc:java数据库链接
insert、delete、update
select
c)Mybatis:持久化框架
4.文件流
a)字节流:
InputStream------FileInputStream
OutPutStrteam----FileOutputStream
b)字符流
Reader----FileReader
Writer----FileWriter
5.处理流
BufferedReader
6.字节流常用的方法
InputStream
read()
close();  //在finally中关闭

InputStream in=null;
byte[] b=new byte[1024];
StringBuilder str=new StringBuilder();
try{
in=new FileInputStream("");
int len=in.read(b);
while(len!=-1){
str.append(new String(b,0,len));
len=in.read(b);
}
}catch(Exception ex){

}finally{
if(in!=null){
try{
in.close();
}catch(Exception e){

}finally{
in=null;
}
}
}

OutputStream
write()
flush();//强制把内存中的数据写入文件
close(); //先执行flush()

OutputStream out=null;
String str="ddddd";
byte[] b=str.getBytes();
try{
out=new FileOutputStream("",true);
out.write(b);
}catch(Exception ex){

}finally{
if(out!=null){
try{
out.close();
}catch(Exception e){

}finally{
out=null;
}
}
}

7.如何把一个对象写到文件中
Student stu=new Student();
stu.setName("");
a)java类必须能够序列化
b)对象流完成




原创粉丝点击