0

Hi i am new to java and i want to know how to access the files in the folder.

My requirement is that, I am successfully compressing an image files and then writing it into a temporary file. Now i want to access each file in the folder so that i can check the size of the files individually to perform some operations.

Please tell me how to access each file in the folder dynamically.

This is the code to compress and then access the folder.

BufferedImage resizeImageBmp = resizeImage(originalImage, type);
ImageIO.write(resizeImageBmp, "png", new File(tempDir + roots[i].getName())); //Compressing the file
String Temp = tempDir; //Path to the temporary folder
//Temp1 = ((Temp.length() / 1024)/1024);
if((Temp.length()) > 6){
  //writeToDir(Temp,failureDir);
  //System.out.println(Temp);
  System.out.println(Temp);
}
else{
  //System.out.println(Temp);
  System.out.println(Temp);
}
1
  • 1
    If you're using Java 7, checkout this, else (or) check out File Commented Jun 4, 2013 at 10:52

1 Answer 1

2

Consider using File.listFiles() listed here.

File tempFile = new File(tempDir);
File[] allFilesInTempDir = tempFile.listFiles();
2
  • how can i use the file names returned individually to perform the calculations?? Commented Jun 4, 2013 at 10:55
  • Can you please elaborate coz this is the 1st time i am working on this and after getting the individual files i need to find the size and compare if it is greater than 6mb then write it into a folder. Commented Jun 4, 2013 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.