I have connected to an ftp location using;
URL url = new URL("ftp://user:[email protected]/" + file_name +";type=i");
I read the content into a byte array as shown below;
byte[] buffer = new byte[1024];
int count = 0;
while((count = fis.read(buffer)) > 0)
{
//check if bytes in buffer is a file
}
I want to be able to check if the bytes in buffer is a file without explicitly passing a specific file to write to it like;
File xfile= new File("dir1/");
FileOutputStream fos = new FileOutputStream(xfile);
fos.write(bytes);
if(xfile.isFile())
{
}
In an Ideal world something like this;
File xfile = new File(buffer);//Note: you cannot do this in java
if(xfile.isFile())
{
}
isFile() is to check if the bytes read from the ftp is file. I don't want to pass an explicit file name as I do not know the name of the file on the ftp location.
Any solutions available?
File.isFile()checks if the file's pathname denotes a regular file (instead of e.g. a directory) in the server's filesystem. The content of your byte array could be anything, but whatever it is, once you write it to your harddisk, it becomes a file (i.e. the content of a file). There is no possible content that cannot become a file once you write it.