Results 1 to 9 of 9
- 01-04-2008, 04:39 PM #1
Creating and checking directories with java code
Hello everyone.
Can someone please give me an example of code so that I can:
- check if an existing directory exists
- create a new directory
Any help would be great.
Thank you. :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-04-2008, 07:45 PM #2
One more thing .. check java documentation for mkdir() and mkdirs() .. they are different and better if you could find that yourself...Java 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"); }
hope it helps ..dont worry newbie, we got you covered.
- 01-04-2008, 07:49 PM #3
Thank you roots. This was what I wanted. :D
Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-05-2008, 01:33 PM #4
Member
- Join Date
- Jan 2008
- Posts
- 3
- Rep Power
- 0
Hi there
I'm totally new at any Forum. Would you hep me to post a question to the forum?
With thanx
Shish
- 01-05-2008, 01:36 PM #5
Member
- Join Date
- Jan 2008
- Posts
- 3
- Rep Power
- 0
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
- 01-05-2008, 01:43 PM #6
Member
- Join Date
- Jan 2008
- Posts
- 3
- Rep Power
- 0
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?
- 01-06-2008, 05:44 PM #7
Member
- Join Date
- Jan 2008
- Posts
- 20
- Rep Power
- 0
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.
- 01-07-2008, 03:17 AM #8
HPSF HOW-TOJava 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());
It works - please Download Apache POI and put in class path before executing above code.dont worry newbie, we got you covered.
- 01-07-2008, 05:41 AM #9
Member
- Join Date
- Jan 2008
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
JSP – getting list of directories
By Java Tip in forum Java TipReplies: 0Last Post: 01-31-2008, 12:51 PM -
getting paths and directories
By marco in forum Java AppletsReplies: 3Last Post: 11-25-2007, 07:28 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 1Last Post: 11-18-2007, 06:21 AM -
java code for checking if a software is installed or not
By heggemony in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 01:19 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks