Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FilenameFilter;
- import java.util.Scanner;
- public class HW01_1 {
- public static void main(String args[]){
- String path;
- Scanner s=new Scanner(System.in);
- path=s.nextLine();
- System.out.println(path);
- File f;
- s.close();
- try{
- f=new File(path);
- File [] files=f.listFiles(new FileFilter());
- double size=0;
- for(File q :files){
- size+=q.length();
- }
- if(files.length!=0)
- System.out.printf("%.2f bytes",size/files.length);
- else
- System.out.println("0");
- }
- catch (Exception e){
- System.exit(-1);
- }
- }
- }
- class FileFilter implements FilenameFilter{
- @Override
- public boolean accept(File dir, String name) {
- name=name.substring(name.length()-4,name.length());
- if(name.equals(".txt"))
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement