Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2008, 05:39 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Creating and checking directories with java code
Hello everyone.

Can someone please give me an example of code so that I can:
  1. check if an existing directory exists
  2. create a new directory
Any help would be great.

Thank you.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-04-2008, 08:45 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Code:
File file = new File("directory path"); if(file.exists()){ System.out.println("File Exists"); }else{ boolean wasDirecotyMade = file.mkdirs(); if(wasDirecotyMade)System.out.println("Direcoty Created"); else System.out.println("Sorry could not create directory"); }
One more thing .. check java documentation for mkdir() and mkdirs() .. they are different and better if you could find that yourself...
hope it helps ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 08:49 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Thank you roots. This was what I wanted.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 02:33 PM
Member
 
Join Date: Jan 2008
Posts: 3
shish is on a distinguished road
Hi there
I'm totally new at any Forum. Would you hep me to post a question to the forum?

With thanx
Shish
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 02:36 PM
Member
 
Join Date: Jan 2008
Posts: 3
shish is on a distinguished road
Hi,
I want to build a java code that can retrieve the Author name of a .doc/.xls file and then it make a folder with the same name of the Author and copies the file into the folder.

Can anybody give me a suggestion?


Shish
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-05-2008, 02:43 PM
Member
 
Join Date: Jan 2008
Posts: 3
shish is on a distinguished road
Hi there

Is possible to retreive the Author name from any file (.doc/.ppt/.xls etc.)?
Is there any java code that can help me to get author of a file?

Please help me?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-06-2008, 06:44 PM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
Here you go, I have more file operations but you can do it some more simpler... Just check it out.


public class TestMaruti implements FilenameFilter {



int iCount = 0;

public String str1 = null;

public void process(String Filter,String FilePath) throws Exception

{


str1=Filter;

File file = new File(FilePath);

String [] str = file.list(this);

File file1 = new File(FilePath+"/"+Filter);

if(!file1.isDirectory())

{

System.out.println(iCount++);

file1.mkdir();

for(int i=0;i<str.length;i++)

{

System.out.println("Writing the file "+str[i]+"....");

File file2 = new File(FilePath+"/"+str[i]);

File file3 = new File(FilePath+"/"+Filter+"/"+str[i]);

moveFiles(file2,file3);

System.out.println("Completed");

}

}


//file.mkdir();

}


public boolean accept(File dir,String s)

{

if(s.startsWith(str1))

{

return true;

}

else

{

return false;

}

}


public static void main (String args[]) throws Exception

{

String path="D:/Maruti/Test";

TestMaruti tm = new TestMaruti();

File allFiles = new File(path);

String [] strFiles = allFiles.list();

for(int j=0;j<strFiles.length;j++)

{

String flName = strFiles[j];

flName=flName.substring(0,flName.indexOf("."));

tm.process(flName,path);

}

}


public void moveFiles(File source,File destination) throws Exception

{

InputStream in = new FileInputStream(source);

OutputStream out = new FileOutputStream(destination);

byte [] buf = new byte[4096];

int len;

while((len=in.read(buf)) > 0 )

{

out.write(buf,0,len);

}

in.close();

out.close();

source.delete();

}

}



Please let me know incase of questions.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-07-2008, 04:17 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Quote:
Originally Posted by shish View Post
Hi there

Is possible to retreive the Author name from any file (.doc/.ppt/.xls etc.)?
Is there any java code that can help me to get author of a file?

Please help me?
Code:
POIDocument document = new HWPFDocument(new FileInputStream("a.doc")); System.out.println(document.getSummaryInformation().getAuthor()); POIDocument workbook = new HSSFWorkbook(new FileInputStream("a.xls")); System.out.println(workbook.getSummaryInformation().getAuthor()); POIDocument show = new HSLFSlideShow(new FileInputStream("a.ppt")); System.out.println(show.getSummaryInformation().getAuthor());
HPSF HOW-TO

It works - please Download Apache POI and put in class path before executing above code.
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-07-2008, 06:41 AM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
Hey I thought author is name is part of the file name

POI needs licesnse i guess ... not sure
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking if Session is new JavaForums Java Blogs 0 03-31-2008 05:50 PM
JSP – getting list of directories Java Tip Java Tips 0 01-31-2008 01:51 PM
getting paths and directories marco Java Applets 3 11-25-2007 08:28 AM
checking if there are equal numbers nalinda New To Java 1 11-18-2007 07:21 AM
java code for checking if a software is installed or not heggemony Advanced Java 1 07-31-2007 02:19 PM


All times are GMT +3. The time now is 10:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org