package homework007;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Text001
{
public static void main(String[] args) throws Exception
{
try
{
//写入
String fileaddress = "e:/TextRw.txt";
FileOutputStream out = new FileOutputStream(fileaddress);
String str = "学号:2012412440 姓名:张伟";
byte[] b = str.getBytes();
out.write(b);
System.out.println("写入成功");
out.close();
//读取
FileInputStream in = new FileInputStream(fileaddress);
int i =0;
String str1 = "";
byte[] b1 = new byte[1024];
while((i=in.read(b1))>0)
{
str1+=new String(b1,0,i);
}
System.out.println(str1);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
![]()