Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

isDirectory()  RSS feed

 
madhuri kh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am uploading a file using FILE TYPE & writing it on server using Multipart Servlet by Orielly. But my problem is it can not save the file on another machine i. e. it does not recognize directory on mapped drive.
isDirectory gives me error message
"Not a directory"
Is isDirectory supposed to look for directory on local machine only?
Please give me some solution
Thanks in Advance
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhuri
I am on Windows machine and from there I have a Mapped drive G: to some system. I tried to do File f = new File("G:\mydir"); f.isDirectory() and that returns me "true". So, I guess isDirectory() works fine on mapped drives.
Try to print some stack trace in your code or something to make sure we are not hiding any exception unknowingly...
Regards
Maulin
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhuri k,
Welcome to JavaRanch!
We don't have many rules here at JavaRanch, but we do have one. Please change your display name to our naming policy of needing more than an initial for a last name. We don't mind initials in the first or middle name, but last names need to be at least 2 characters.
Thanks pardner!
As far as your question goes, are you saying that the server has a mapped drive and you are checking, from within the servlet, whether or not a directory in that mapped drive is a directory or not? Perhaps if you could either explain the whole setup, or perhaps give some sample code, we can help you out better (my apologies for not fully "getting it").
If you are testing the mapped drive itself, then it should be recognized as a directory.
 
madhuri kh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maulin & Jason,
I tried maulin way & it does recognize the mapped drive.
But somehow its not working in my servlet code.
YES my server has a mapped drive and I am checking, from within the servlet, whether or not a directory in that mapped drive is a directory or not?
Part of my Servlet code is as follows
****************************************************
public MultipartRequest(HttpServletRequest request,
String saveDirectory,
int maxPostSize,
String encoding,
FileRenamePolicy policy) throws IOException {
// Sanity check values
if (request == null)
throw new IllegalArgumentException("request cannot be null");
if (saveDirectory == null)
throw new IllegalArgumentException("saveDirectory cannot be null");
if (maxPostSize <= 0) {
throw new IllegalArgumentException("maxPostSize must be positive");
}
// Save the dir
File dir = new File(saveDirectory);
// Check saveDirectory is truly a directory
if (!dir.isDirectory())
throw new IllegalArgumentException("Not a directory: " + saveDirectory);
******************************************************************
Well
My mapped folder is like this
websites$on Kard(G
(It means I have folder mapped to G: rather than disk drive)
Where Kard is the machine name & websites is a folder or directory on the machine so actual path is \\kard\d:\websites
Now My question is can I access this folder without using mapped drive letter like this \\kard\d&\websites
I would really appreciate if u can help me.
Thanks for your previous replies
Madhuri
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhuri
Sorry for not replying on your private notification. I didn't reply as I got confused
I know that we can map drive to the network folder via "My Computer->Map Network Drive..." in Windows2k for e.g. but here it seems you have mapped a "folder" to another network folder/drive....How is that possible??
Please bare w/ me. I'm not a great user of Windows.
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...
I get it now...You can't achieve what you are trying to do as java.io.File would work for "local" machine and so we have to "map" a drive. Also, its wiered that you want to upload the file to the other machine on the network directly...use FTP instead via URLConnection and then write stream of bytes for the file...
Regards
Maulin
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!