您的位置:首页 > 编程语言 > Java开发

我的java实验

2015-09-13 18:52 393 查看
public class InputStreamDemo2 {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file1=new File("C:/Users/Student-1/Desktop/面对巨人片段.rmvb");
File file2=new File("C:/Users/Student-1/Desktop/面对巨人片段_复制.rmvb");
FileInputStream input=new FileInputStream(file1);
FileOutputStream output=new FileOutputStream(file2);
int len=input.read();
while(len!=-1){
output.write(len);
len=input.read();
}
input.close();
output.close();

}

}

public class ExceptionDemo {

public static void main(String[] args)throws IOException {

Scanner sc = null;
//捕获异常
try {
sc = new Scanner( new BufferedReader(new FileReader("D:/shiyan6/src/ExceptionDemo.java")));
while (sc.hasNext()) {   
           System.out.println(sc.next()); 
   }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (sc != null) { 
sc.close();//关闭数据流
}
}
 

}

}

public class InputStreamDemo {

public static void main(String[] args) throws IOException {
// 第一种方法
File file=new File("D:/CX workspace/IoDemo/src/InputStreamDemo.java");

System.out.println("字节数是:"+file.length());

//第二种方法
FileInputStream input=new FileInputStream(file);
int i;
int count=0;
while((i=input.read())!=-1){
count++;
}
System.out.println("字节数是:"+count);
input.close();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: