?
Solved

renameTo for directories

Posted on 1998-06-19
3
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
ragnar earned 150 total points
ID: 1223416
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
ID: 1223417
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
ID: 1223418
yes, the num of arguments is only for the command line.  Good luck!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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