Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

create files and a drive for them

Thread view: 
oqestra@yahoo.com - 29 Jul 2006 16:47 GMT
Hello, super java programmers!

I've been a fan of java programming for some years but still around
with some very basic input-output stuff.
I am currently having a problem with file creation, that I don't know
how to generate many files at the same time. I add a button on my frame
already, so please tell me how I can create a shortcut of an already
existing drive and then add some files in it when I click that button ?

Thanks a lot
Michael Rauscher - 29 Jul 2006 23:23 GMT
oqestra@yahoo.com schrieb:
> Hello, super java programmers!
>
[quoted text clipped - 4 lines]
> already, so please tell me how I can create a shortcut of an already
> existing drive and then add some files in it when I click that button ?

I don't know exactly if I understand you correctly, but perhaps this one
helps:

public void createSomeFiles( String path ) throws IOException {
    File directory = new File(path);
    if ( !directory.isDirectory() )
        throw new IllegalArgumentException( path +
                " denotes no directory." );

    for ( int i = 0; i < 20; i++ ) {
        StringBuilder fileNameBuilder =
                new StringBuilder( directory.getAbsolutePath() );
        fileNameBuilder.append( File.separator );
        fileNameBuilder.append( "File" );
        fileNameBuilder.append( i );

        File f = new File(fileNameBuilder.toString());
        f.createNewFile();
    }
}

Bye
Michael
Mark Space - 30 Jul 2006 03:05 GMT
> Hello, super java programmers!
>
[quoted text clipped - 4 lines]
> already, so please tell me how I can create a shortcut of an already
> existing drive and then add some files in it when I click that button ?

For the existing drive, first you need to know what the existing drives
are.  Use the listRoots() method.

http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#listRoots()

You'll have to list all the roots (drive letters), throw away the ones
you don't want, if any (maybe you don't want A: and B:, for example, or
you don't want the CDROM).  Then you'll need to make a new button for
each drive left.

Then when the said button is clicked, you have to switch the window,
frame or whatever, and present the user with a new file listing.  Any
new files go in the current directory, so you'll have to store that for
use as well.

Disclaimer: I haven't tried this yet, or used listRoots().  Read the
docs first, make sure it does what you want.
Mark Space - 30 Jul 2006 03:10 GMT
Oh yes, one more thing:  Why go to all this trouble?

Why not just use the FileChooser?  All the hard work is done for you...

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFileChooser.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.