Solved

renameTo for directories

Posted on 1998-06-19
3
247 Views
Last Modified: 2010-03-30
I tried to rename a directory and found the logic of it
was no good. It is suppose to be if e:\cache\one.txt
exists then rename e:\cache to e:\cache1. I tried defining
the variables as File such as f1=new file("e:\cache") but
no luck. I dont understand the arg[] idea too well. Can you
tell me a good source on addition instructions for renameTo?
0
Comment
Question by:johnh619
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
ragnar earned 50 total points
Comment Utility
Do the following:

File f = new File("E:" + File.separator + "cache");

the backslash character was escaping c, which meant "stay on the same line."  The file separator is a platorm neutral version of a / or \ or : directory separator.  You might consider using a FileDialog to prompt the user for the location of the cache.  if you want details on how to do this, just email me and i'll show you some examples.

Regarding args[],

your main function looks like this:

  public static void main(String[] args)

args is an array that refers to the command line arguments.  if the program has any arguments you can pick them up.  For example if the program was invoked like:

% java myProgram firstArg secondArg

then in your code you could reference the arguments like:

String frist  = args[0];
String second = args[1];

Notice that this is different from C++ where args[0] refers to the name of the program, while in Java it refers to the first argument.

Good luck!
0
 

Author Comment

by:johnh619
Comment Utility
I assume then that number args are only for the command line.
So I am not wanting to use the command line as input. I will
use choice box. I think your suggestion for file separator may
fix my problems though, so thanks. John H
0
 
LVL 1

Expert Comment

by:ragnar
Comment Utility
yes, the num of arguments is only for the command line.  Good luck!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now