Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package filter;
- import java.io.File;
- import java.io.FilenameFilter;
- public class Filter{
- public static void main(String[] args) {
- int i=0,zbir=0;
- float prosGol;
- File f = null;
- File[] filovi;
- try{
- // create new file
- f = new File("C:\\");
- // create new filename filter
- FilenameFilter fileNameFilter = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- if(name.lastIndexOf('.')>0)
- {
- // get last index for '.' char
- int lastIndex = name.lastIndexOf('.');
- // get extension
- String str = name.substring(lastIndex);
- // match path name extension
- if(str.equals(".txt"))
- {
- return true;
- }
- }
- return false;
- }
- };
- // returns pathnames for files and directory
- filovi = f.listFiles(fileNameFilter);
- // for each pathname in pathname array
- for(File k:filovi)
- {
- i++;
- zbir +=k.length();
- // prints file and directory paths
- System.out.println(k);
- }
- prosGol=(float)zbir/i;
- System.out.println("Prosecna golemina"+prosGol);
- }catch(Exception e){
- // if any error occurs
- System.out.println("Error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement