package lianxi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class IOdemo {
public static void main(String[] args)
{
String a = "d:/java" ;
String b ="extRw.txt" ;
File file = new File(a,b) ;
File c = new File(a) ;
//判断目录是否存在
if(!c.exists())
{
c.mkdirs();
}
try
{
//创建
file.createNewFile() ;
//输出流
FileOutputStream out = new FileOutputStream(file) ;
//写入内容
String st = "123456;\r\n付士亮";
//转换到byte[]
byte[ ] by = st.getBytes( ) ;
//写入
out.write(by);
//关闭流,释放资源
out.close();
System.out.println("写入成功!");
//输入流
FileInputStream in = new FileInputStream("d:/java/extRw.txt") ;
//装在数据的数组,
byte[ ] be = new byte[1024] ; //1k大小
int i =0;
String s ="" ;
while((i=in.read(be))>0)
{
//组合数据
//参数1 :0 起始位置, i : 数据长度
s +=new String(be,0,i) ;
}
System.out.println("输入成功!");
System.out.println("s=" +s);
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

