Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie Q using javaranch.common package  RSS feed

 
Omar Barrera
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have been attempting to use the javaranch.common package that I installed with an application that I am writing in java. I am fairly new to java and am having some transitional problems. Essentially my program will retrieve some files via ftp and rename and append the run date to the file name. I decided to use the com.javaranch package because it seemed like it has lot of the funtionality that I need. Anyway...here is a segment of my code that retreives the files and then will rename the file with the date appended to the file name. I am stuck...any pointers are greatly appreciated. Basically I need help with calling the rename function, using the convertDateToString method. Am using the imported methhods properly? I placed question marks in the area that I am stuck in. Thank You.
.
.
.

//Create new file objects
File clmDisb = new File("c:/clm_disb.clm");
File clmPay = new File("c:/clm_pay.lbx");

Date today = new Date();

???clmDisb.rename("c:/clm_disb" + convertDateToSTring(today)???);


//method to return date
public static String convertDateToString(Date today){
Calendar cal = Calendar.getInstance();
cal.setTime(today);
return "_"
+ (cal.get(Calendar.MONTH)+1)
+ (cal.get(Calendar.DATE)-1)
+ cal.get(Calendar.YEAR);
}
.
.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
method declaration in com.javaranch.common.Files:
public static void rename( String source , String dest )

Your code:
clmDisb.rename("c:/clm_disb" + convertDateToSTring(today));

I only see one String in the parens. You need something more like:
Files.rename( FileNameYouAreConvertingFrom , FileNameYouAreConvertingTo );

Note that it is a static method, so you call it using the class name that you find the method in (in this case, Files)

And you don't want the whole path, just the name of the file.
Something like
Files.rename( "clm_disb.clm" , "clm_disb" + convertDateToSTring( today ) );
[ August 17, 2005: Message edited by: Marilyn de Queiroz ]
 
Kristin Stromberg
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, be careful with the following:


Should probably be
 
Omar Barrera
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying promptly.

Omar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!