Hello all I am using if (canRead && canWrite && !isFloppy && isDrive) and it only will read off the first drive it finds "C:\", I have a HDD and a SSD, it wont detect the ssd for somereason "D:\" for some reason anyehelp? Thanks.
Sorry guys slipped my mind to include the vars:
package javaapplication3;
import java.io.*;
import javax.swing.filechooser.FileSystemView;
class filler
{
public static void main(String ar[]) throws InterruptedException
{
FileSystemView fsv = FileSystemView.getFileSystemView();
File[] f = File.listRoots();
for (int i = 0; i < f.length; i++) {
String drive = f[i].getPath();
String displayName = fsv.getSystemDisplayName(f[i]);
String type = fsv.getSystemTypeDescription(f[i]);
boolean isDrive = fsv.isDrive(f[i]);
boolean isFloppy = fsv.isFloppyDrive(f[i]);
boolean canRead = f[i].canRead();
boolean canWrite = f[i].canWrite();
//(type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile"))
if (canRead && canWrite && !isFloppy && isDrive) {
try {
File file = new File(drive +"log_22_2112321321312.log");
if (file.createNewFile()){
System.out.println("File is created!");
}
if (file.exists()){
System.out.println("Drive found " + drive);
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (canRead && canWrite && !isFloppy && isDrive &&(type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile"))) {
try {
File file = new File("log_22_2112321321312.log");
if (file.createNewFile()){
System.out.println("File is created!");
}
if (file.exists()){
System.out.println("Drive found " + drive);
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Are you using File.listRoots()? Check the output of the following:
File[] roots = File.listRoots();
for (File r : roots)
System.out.println(r);
It's possible that your SSD is being detected but isn't passing your conditional's criteria. Code inside your conditional will only be executed if the specified condition is met. Run your code without the condition to see if the drive isn't actually being recognized, or whether it's not appearing due to a logic error or some other volume setting.
Related
I have an external mass storage device connected to an Android device. There are several .BIN files in the root directory that I need to read into my app. I am able to connect to the device and receive usb permission using UsbDeviceConnection.
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String output = outputTV.getText().toString();
String action = intent.getAction();
outputTV.setText(outputTV.getText() + "\n" + " ACTION: " + action);
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
if (device.getInterfaceCount() > 0) {
usbIntf = device.getInterface(0);
usbEndIn = usbIntf.getEndpoint(0);
usbEndOut = usbIntf.getEndpoint(1);
usbConnection = mUsbManager.openDevice(device);
usbConnection.claimInterface(usbIntf, true);
byte[] buffer = new byte[usbEndIn.getMaxPacketSize()];
StringBuilder str = new StringBuilder();
int retVal = usbConnection.bulkTransfer(usbEndIn, buffer, usbEndIn.getMaxPacketSize(), 2000);
for (int i = 2; i < buffer.length; i++) {
if (buffer[i] != 0) {
str.append((char) buffer[i]);
}}}}}}}}};
Once I'm connected I am able to see that I have one Mass Storage interface with 2 Bulk Transfer endpoints (one in, one out).
When using usbConnection.bulkTransfer I receive -1 back and an empty buffer. So, I'm having trouble receiving data. Once past that hurdle, what will the data look like? How do I continue to pull all of the files from the device? Is there a way to transfer the data file by file to my app? Is there an all together better way of approaching this?
Well, I ended up going a totally different route with this. I am now using standard java.io.File and working my way through the directory structure. My code is not yet refined, but here is the gist of it...
private void setupFileIO() {
File storageDir = new File("/storage");
File files[] = storageDir.listFiles();
File directory = null;
if (files != null && files.length > 0) {
for (File f : files) {
if (f.isDirectory() && f.getPath().toLowerCase().contains("usb") && f.canRead()) {
directory = f;
break;
}
}
}
if (directory != null && directory.canRead()) {
File file[] = directory.listFiles();
if (file != null && file.length > 0) {
for (int i = 0; i < file.length; i++) {
String filePath = file[i].getPath();
String extension = Files.getFileExtension(filePath);
if (file[i].isFile() && file[i].canRead() && extension.equalsIgnoreCase("bin")) {
try {
byte[] r = Files.toByteArray(file[i]);
String result = BaseEncoding.base16().encode(r);
// do something with result
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
So I have a method that reads all the files in a folder and creates new classes in a List with the variables read from the files. For some reason it doesn't ever get past the if(mainDir.isDirectory()){ part, even though the paths are correct and I double checked the folders were there.
public static void loadIntoClass(String dir, int temp){
try {
File mainDir = new File(dir);
if(mainDir.isDirectory()){ //Checks if the dir is a folder and not a file
String[] fileNames = mainDir.list(); //Grabs a list of all the filenames in the dir
for(int x = 0; x > fileNames.length; x++){ //loops through all the files
File currFile = new File(dir + fileNames[x]); //Creates the object we will be gathering information from
if(currFile.isFile()){ //Checks to make sure the file is a file and not a folder
BufferedReader br = new BufferedReader(new FileReader(currFile));
String line = br.readLine();
int currLoop = 1;
boolean collides = false;
while(line != null){ //Will keep checking files until it reaches a blank line
currLoop ++; //Keeps track of how many times it loops
test = line.split("="); //Splits up the variable from the declaration
String toString = test[0].trim(); //Trims off any extra blank spaces on either side
System.out.println("Reading: " + toString + " on line " + currLoop); //For debugging
String toString2 = test[1].trim(); //Trims the second string
parse[currLoop] = Integer.parseInt(toString2); //Turns the string into an integer then puts it into the array
if(toString.equalsIgnoreCase("Collides")){
if(toString2.equalsIgnoreCase("true")){
collides = true;
}
}
if(toString.equalsIgnoreCase("Image Path")){
//path = toString2;
}
line = br.readLine();
}
if(temp == 1){
types.add(new Type(parse[1], parse[2], parse[3], parse[4], parse[5], parse[6], parse[7]));
}
if(temp == 2){
tiles.add(new Tiles(parse[1], collides, null));
}
if(temp == 3){
abilities.add(new Abilities(parse[1], parse[2], parse[3], parse[4]));
}
br.close();
}
}
}
} catch(Exception e) {
System.err.println("ERROR: " + e);
}
}
After that if I change it some other path like "C:/test" it works only to freeze at the for loop. Here's the declaration:
loadIntoClass("C:/Program Files(x86)/GameNameHere/config/enemies", 1);
The methods isDirectory() and isFile() doe not work if the underlying FS-Objects do not exist.
There are multiple possible issues, which you are not taking into consideration...
Your not checking to see if the dir exists
Your not making sure to close your files in case of an read error (or other associated error)
You making life tough for yourself using File#list, instead use File#listFiles which will return an array of File
Make better use of exceptions...
For example...
public static void loadIntoClass(String dir, int temp) throws IOException {
File mainDir = new File(dir);
if(mainDir.exists) { // Check to see if the abstract path actually exists
if (mainDir.isDirectory()){ //Checks if the dir is a folder and not a file
File[] fileNames = mainDir.listFiles(); //Grabs a list of all the filenames in the dir
//String[] fileNames = mainDir.list(); //Grabs a list of all the filenames in the dir
if (fileNames != null && fileNames.length > 0) {
//for(int x = 0; x > fileNames.length; x++){ //loops through all the files
for(File currFile : fileNames){ //loops through all the files
//File currFile = new File(dir + fileNames[x]); //Creates the object we will be gathering information from
if(currFile.isFile()){ //Checks to make sure the file is a file and not a folder
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(currFile));
String line = null;
int currLoop = 1;
boolean collides = false;
while((line = br.readLine()) != null){ //Will keep checking files until it reaches a blank line
//...//
}
//...//
// Make sure you make all best attempts to close the reader...
} finally {
try {
br.close();
} catch (Exception exp) {
}
}
}
}
} else {
// You may not care, but...
throw new IOException(dir + " does not contain any files");
}
} else {
throw new IOException(dir + " is not a directory");
}
} else {
throw new IOException(dir + " does not exist");
}
}
I have the following method to write an array to a text file. If a existing text file is given then it works fine but if a file that doesn't exist is given neither try-catch will run the code to restart the method. I'm not given any error or anything but the catch block won't run. I didn't think i would need to catch for an IOException but the code won't even run if i don't do that. So yea, anyone know how i can get this to work?
Edit: Forgot to mention the getInput method prompts the user for input.
private static void openFileWriter(String prompt, boolean append, int wordsperline, String[] story) {
try {
try {
save = new PrintWriter(new FileWriter(getInput(prompt), append));
wordsperline = 0;
save.println("");
save.println("");
save.println("Story start");
for (int x = 0; x <= story.length-1; x++) {
if (story[x] == null) {
} else {
if (wordsperline == 21) {
save.println(story[x]);
wordsperline = 0;
} else {
save.print(story[x]);
wordsperline++;
}
}
}
save.close();
} catch (FileNotFoundException e1) {
openFileWriter("File not found", append,wordsperline,story);
}
} catch (IOException e) {
// TODO Auto-generated catch block
openFileWriter("File not found", append,wordsperline,story);
}
}
If the File does not exist you cannot write to it, in your catch block you are trying to write the error to the File that doesn't exist. Also, I think you only need 1 catch block here, and note that one of the if statement blocks is empty.
try this:
try
{
save = new PrintWriter(new FileWriter(getInput(prompt), append));
wordsperline = 0;
save.println("");
save.println("");
save.println("Story start");
for(int x = 0; x <= story.length-1; x++)
{
if (story[x] == null)
{
}
else
{
if (wordsperline == 21)
{
save.println(story[x]);
wordsperline = 0;
}
else
{
save.print(story[x]);
wordsperline++;
}
}
}
save.close();
}
catch (FileNotFoundException e1)
{
System.err.println(e1.getMessage());
}
catch (IOException e)
{
System.err.println(e.getMessage());
}
See FileWriter javadoc.
Quoting from the constructor doc:
Throws:
IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
If you pass it a filename that doesn't exist, but is a legal filename in a location where you have permission to write, it simply creates the file.
Your code in fact does reach the catch blocks if you pass it a directory (somewhat oddly, it catches a FileNotFoundException in this situation for me rather than the documented IOException).
To check if a file exists, see File javadoc
Try this version and send the stack trace when you get the exception:
public static List<String> splitByLength(String filename, int length) {
List<String> splitWords = new ArrayList<String>();
for (int i = 0; i < str.length(); i += length) {
splitWords
.add(str.substring(i, Math.min(str.length(), i + length)));
}
return splitWords;
}
private static void openFileWriter(String prompt, boolean append,
int wordsperline, String[] story) {
PrintWriter save = null;
try {
save = new PrintWriter(new FileWriter("c:\\test.txt", append));
wordsperline = 0;
save.println("");
save.println("");
save.println("Story start");
for (int x = 0; x <= story.length - 1; x++) {
if (story[x] != null) {
List<String> splitWords = splitByLength(story[x], 21);
for (String line : splitWords) {
save.println(line);
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (save != null) {
save.close();
}
}
}
import java.io.*;
import java.io.File;
import java.io.FilenameFilter;
public class YDSearch{
public void listFiles(String dir) throws IOException{
File directory = new File(dir);
if (!directory.isDirectory()) {
System.out.println("No directory provided");
return;
}
//create a FilenameFilter and override its accept-method
FilenameFilter filefilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
//if the file extension is .mp3 return true, else false
return name.endsWith(".mp3")||name.endsWith(".mp4")||name.endsWith(".3gp")
||name.endsWith(".mov")||name.endsWith(".avi")||name.endsWith(".wmv");
}
};
String[] filenames = directory.list(filefilter);
DataOutputStream output = new DataOutputStream(new FileOutputStream("C:/Users/Jonathan/Desktop/YouDetect/SearchByFileType/AllMediaFiles.dat"));
for (String name : filenames) {
output.writeUTF(dir + name);
}
output.close();
DataInputStream input = new DataInputStream(new FileInputStream("C:/Users/Jonathan/Desktop/YouDetect/SearchByFileType/AllMediaFiles.dat"));
DataOutputStream output2 = new DataOutputStream(new FileOutputStream("C:/Users/Jonathan/Desktop/ReadyForAnalysis.dat"));
for (String name : filenames) {
FileInputStream in = new FileInputStream(input.readUTF());
int byteCounter = 0;
int rowCounter = 0;
long bufferCounter = 0;
if(name.endsWith(".mp3")){
byte[] b = new byte[36];
int read = in.read(b, 0, 36);
if (byteCounter != 1000){
if (rowCounter == 1){
System.out.println("\n");
rowCounter = 0;
}
output2.writeUTF(org.apache.commons.codec.binary.Hex.encodeHexString(b)+ " " + dir + name);
bufferCounter ++;
rowCounter ++;
}else{
byteCounter = 0;
try{
Thread.sleep(200);
}catch(InterruptedException e) {
}
}
}
else if(name.endsWith(".mp4")){
byte[] b = new byte[29];
int read = in.read(b, 0, 29);
if (byteCounter != 1000){
if (rowCounter == 1){
System.out.println("\n");
rowCounter = 0;
}
output2.writeUTF(org.apache.commons.codec.binary.Hex.encodeHexString(b)+ " " + dir + name);
bufferCounter ++;
rowCounter ++;
}else{
byteCounter = 0;
try{
Thread.sleep(200);
}catch(InterruptedException e) {
}
}
}
//System.out.println("====================");
}
output2.close();
input.close();
DataInputStream input2 = new DataInputStream(new FileInputStream("C:/Users/Jonathan/Desktop/ReadyForAnalysis.dat"));
for (String name : filenames) {
System.out.println(input2.readUTF()+"\n");
}
}
public void checkHeaderSC(String allFiles)throws IOException{
}
public static void main(String[] args) throws IOException {
YDSearch YDSearch = new YDSearch();
YDSearch.listFiles("C:/Users/Jonathan/Desktop/YD Tests/1) High Quality/");
YDSearch.listFiles("C:/Users/Jonathan/Desktop/YD Tests/2) Medium Quality/");
YDSearch.listFiles("C:/Users/Jonathan/Desktop/YD Tests/3) Low Quality/");
YDSearch.checkHeaderSC("C:/Users/Jonathan/Desktop/YouDetect/SearchByFileType/ReadyForAnalysis.dat");
}
}
Hey there, having a little issue with the above coding and hoped someone here might be able to help. This is sort of a partial version of the code as the real one has 4 more if/else if statements involved.
The program compiles and begins to run fine. It produces several results back from the file that is being read into/then out of again in input2 but then stops, produces no more results and gives the error:
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:323)
at java.io.DataInputStream.readUTF(DataInputStream.java:572)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at YDSearch.listFiles(YDSearch.java:85)
at YDSearch.main(YDSearch.java:93)
Anybody know why this might be happening and have a solution they could share?
I've also tried making the variable 'b' to be inside of an if statement but that doesn't work because of scope. If b was defined by if's then there would only need to be one if statement to output to the file
Please let me know if you've got any ideas, I'd really appreciate it :)
As far as I can see, you don't always put out an output record for every name, only for when the name matches one of your patterns. However, you do try to read an input record for every name.
Ergo, if you have any filenames that don't match the patterns you try to read more than you write, and you will get the EOF.
EDIT:
In more detail, the problem is that you get a list of all the files that end with "mp3", "mp4", "3gp", "mov", "avi or "wmv". You then process that list, and write out something into C:/Users/Jonathan/Desktop/ReadyForAnalysis.dat for each "mp3" and "mp4" file. You then assume that for each entry in your list of files, that you will have an entry in ReadyForAnalysis.dat. However, if there are any files ending in "3gp", "mov", "avi or "wmv" then this will not hold true.
I am coding a class that compares the files of two directories via comparing the Byte arrays of each file. I am however not getting the expected results; identical files are not being resolved as identical files.
First problem:
Matching the files Byte[] with equals() resolves to false with matching files (Checked with only one file as to circumvent the possible index misalignment issue; the check still resolves to false.).
Second problem:
When using Vector's containsAll() for checking that both Vectors of Byte[] match (One Vector per directory with Byte[] for each file) this check results in false even with identical directories (This check has been removed from the code below.). So is there an issue with the way I am aligning the two vectors? (I have checked this with using two directories with matching files in the same order loaded into matching indeces; this still results in a Vector mismatch).
Third problem:
When there are subdirectories in the directories being checked a file not found exception is thrown stating that access is denied. Why is this happening? How can I circumvent this? I do not want to check the files contained within the subdirectories, but I am designing the code so that the end user need not worry about the subdirectories of the directories being compared. This only happens when there are subdirectories, it work fine when there are no subdirectories in the directories being checked.
Example Exception:
Byte reading error!
Byte reading error!
java.io.FileNotFoundException: C:\Dir1\Dir2\Dir3\Dir4\SubDir (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at tools.filesystem.filecomparison.FileComparator.getBytes(FileComparator.java:166)
at tools.filesystem.filecomparison.FileComparator.main(FileComparator.java:102)
java.io.FileNotFoundException: C:\Dir1\Dir2\Dir3\Dir4\SubDir Files (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at tools.filesystem.filecomparison.FileComparator.getBytes(FileComparator.java:166)
at tools.filesystem.filecomparison.FileComparator.main(FileComparator.java:111)
Here is the code:
package tools.filesystem.filecomparison;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import java.util.Vector;
public class FileComparator
{
public static void main(String[] args)
{
String workingDir1 = "";
String workingDir2 = "";
File[] fileArr1 = null;
File[] fileArr2 = null;
Vector<File> fileVec1 = new Vector<File>();
Vector<File> fileVec2 = new Vector<File>();
Scanner console = new Scanner(System.in);
while (true)
{
System.out.println("Enter working directory one . . . .");
workingDir1 = console.nextLine();
workingDir1.replace("\\", "\\\\");
System.out.println("Enter working directory two . . . .");
workingDir2 = console.nextLine();
workingDir2.replace("\\", "\\\\");
File folder1 = new File(workingDir1);
File[] listOfFiles1 = folder1.listFiles();
File folder2 = new File(workingDir1);
File[] listOfFiles2 = folder2.listFiles();
fileArr1 = listOfFiles1;
fileArr2 = listOfFiles2;
System.out.println("\nWorking Directory 1 Files\n");
for (int i = 0; i < listOfFiles1.length; i++)
{
if (listOfFiles1[i].isFile())
{
System.out.println(" " + listOfFiles1[i].getName());
}
/* else if (listOfFiles1[i].isDirectory())
{
System.out.println("Directory " + listOfFiles1[i].getName());
}*/
}
System.out.println("\nWorking Directory 2 Files\n");
for (int i = 0; i < listOfFiles2.length; i++)
{
if (listOfFiles2[i].isFile())
{
System.out.println(" " + listOfFiles2[i].getName());
}
/* else if (listOfFiles2[i].isDirectory())
{
System.out.println("Directory " + listOfFiles2[i].getName());
}*/
}
for (File fle : fileArr1)
{
fileVec1.add(fle);
}
for (File fle : fileArr2)
{
fileVec2.add(fle);
}
if (fileVec1.containsAll(fileVec2))
break;
else
{
System.out.println("Directories do not contain the same files!\nContinue anyways? y/n?");
if (console.nextLine().equalsIgnoreCase("y"))
break;
else if (console.nextLine().equalsIgnoreCase("n"))
continue;
}
}
Vector<Vector<File>> alignedVectors = align(fileVec1, fileVec2);
fileVec1 = alignedVectors.elementAt(0);
fileVec2 = alignedVectors.elementAt(1);
Vector<byte[]> fileByteVect1 = new Vector<byte[]>();
Vector<byte[]> fileByteVect2 = new Vector<byte[]>();
try
{
fileByteVect1 = getBytes(fileVec1);
}
catch (IOException e)
{
System.out.println("Byte reading error!");
e.printStackTrace();
}
try
{
fileByteVect2 = getBytes(fileVec2);
}
catch (IOException e)
{
System.out.println("Byte reading error!");
e.printStackTrace();
}
boolean[] check = new boolean[fileByteVect1.capacity()];
int i1 = 0;
//debug
for (byte[] e : fileByteVect1)
{
System.out.println("Vector 1 count " + i1);
System.out.println(e.toString());
for (byte b : e)
{
System.out.print(b + " ");
}
i1++;
}
int i2 = 0;
//debug
for (byte[] e : fileByteVect2)
{
System.out.println("Vector 2 count " + i2);
System.out.println(e.toString());
for (byte b : e)
{
System.out.print(b + " ");
}
i2++;
}
if (fileByteVect1.size() == fileByteVect2.size())
{
System.out.println(fileByteVect1.size());
for (int i = 0; i < fileByteVect1.size(); i++ )
{
if (fileByteVect1.elementAt(i).equals(fileByteVect2.elementAt(i)))
{
check[i] = true;
System.out.println("File at index " + i + " are identical");
}
else
{
check[i] = false;
System.out.println("File at index " + i + " are not identical");
}
}
}
else
System.out.println("Files do not match!");
}
public static Vector<Vector<File>> align(Vector<File> fileVect1, Vector<File> fileVect2)
{
Vector<Vector<File>> mainBuffer = new Vector<Vector<File>>();
Vector<File> bufferFileVect = new Vector<File>();
for (File fle1 : fileVect1)
{
for (File fle2 : fileVect2)
{
if (fle1.getName().equals(fle2.getName()))
bufferFileVect.add(fle2);
}
}
mainBuffer.add(fileVect1);
mainBuffer.add(bufferFileVect);
return mainBuffer;
}
public static Vector<byte[]> getBytes(Vector<File> fileVector) throws IOException
{
Vector<byte[]> outVector = new Vector<byte[]>();
for (File file : fileVector)
{
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
if (length > Integer.MAX_VALUE)
{
System.out.println("File is too large!");
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int) length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)
{
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length)
{
throw new IOException("Could not completely read file " + file.getName());
}
// Close the input stream and return bytes
outVector.add(bytes);
is.close();
}
return outVector;
}
}
The equals function isn't doing a deep comparison, rather for a byte[] you're comparing addresses. Instead you should use
Arrays.equals(fileByteVect1.elementAt(i), fileByteVect2.elementAt(i))
to perform the deep comparison of the byte arrays.
More detail on Arrays.equals.
As for your third question, you're not actually filtering for just files. When you iterate through to print out the filename you should construct the Vector storing the files:
for (File fle : fileArr1) {
if (fle.isFile()) {
fileVec1.add(fle);
System.out.println(" " + fle.getName());
}
}
You will, of course, have to do this for fileArr2 and fileVec2 as well.
Simple. The equals(Object) method on an array is inherited from Object, and hence is equivalent to the == operator; i.e. it is just a reference comparison.
This is specified in JLS 6.4.5.
If you want to compare arrays by value, use the java.util.Arrays.equals(array1, array2) methods. There are overloads for arrays of each primitive type and arrays of Object.
(Note that it is the semantics of each element type's implementation of equals method that determines if Arrays.equals(Object[], Object[]) is a "deep" or "shallow" comparison.)
FOLLOW UP
I suspect that the third problem happens because your application is trying to open the subdirectory as a file. That won't work. Instead, you need to:
Use File.isFile() and File.isDirectory() to determine whether you should be reading the directory entries as files or dirctories (or not at all).
For a directory, you should recursively use File.listFiles() or similar to iterate over the subdirectory contents.