• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Queries

Hi all,

I have 2 following queries.

a. How do I chk in Win2K/Win NT whether the logged in User logged in is having administrative right uing Java ?
b. Uing Java I would like to copy Folder(sub-folders) from one location to another

Thanks in advance

Regard
Tridib
0
tridib
Asked:
tridib
  • 3
  • 2
  • 2
  • +1
1 Solution
 
allahabadCommented:
System.out.println( "os : "+ System.getProperty("os.name"));
0
 
allahabadCommented:
For question b. here is example for 1.4
http://javaalmanac.com/egs/java.nio/File2File.html
0
 
allahabadCommented:
file Copy :

public static void copyFile(File source, File target) throws IOException
{
    FileInputStream in = new FileInputStream(source);
    FileOutputStream out = new FileOutputStream(target);
    byte[] buffer = new byte[1024];
    int read = -1;
    while ((read = in.read(buffer, 0, buffer.length)) != -1)
    {
        out.write(buffer, 0, read);
    }
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tridibAuthor Commented:
hi allahabad,

thanks for yr reply.

however as per my question b) i am looking for folder copy from one location to another, alongwith the subfolders.

looking for yr help

regards
tridib
0
 
glottisCommented:
u mean the old DOS style way. then i think the sollution by allahbad is ok only changes u have to make is to add recursion in to it.
0
 
tridibAuthor Commented:
hi allahabad,

thanks for yr reply.

however as per my question b) i am looking for folder copy from one location to another, alongwith the subfolders.

looking for yr help

regards
tridib
0
 
JituCommented:
listening...
0
 
glottisCommented:
u can see if the File is a directory or not..
File f = new File("c:\java");
if (f.isDirectory) {
 ... do some work
}

create a method which accepts to File objects (File source, File target)

see if source is directory if it is the make a new directory by that name in target.

then list all files in source with the command source.listAll() // i think better check in java.io.File.

then recurse the method you have made.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now