package io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileTest {
public static void main(String[] args){
File file=new File("D:","test.txt");
FileInputStream in=null;
FileOutputStream out=null;
try{
out=new FileOutputStream(file);
out.write("黄昏".getBytes());
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
if(out!=null){
try{
out.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
try{
in=new FileInputStream(file);
byte[]content=new byte[1024];
int length=in.read(content);
System.out.println("文件中的信息是:"+new String(content,0,length));
}catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileTest {
public static void main(String[] args){
File file=new File("D:","test.txt");
FileInputStream in=null;
FileOutputStream out=null;
try{
out=new FileOutputStream(file);
out.write("黄昏".getBytes());
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
if(out!=null){
try{
out.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
try{
in=new FileInputStream(file);
byte[]content=new byte[1024];
int length=in.read(content);
System.out.println("文件中的信息是:"+new String(content,0,length));
}catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}
}
}
文件中的信息是:黄昏