pdf - How do I use different prefixes when renaming multiple files in Java? -


I'm trying to create a Java app (with swing) which designates PDF files with a set naming convention is. Currently files are named:

  1.pdf, 2.pdf ...... 10.pdf, 11.pdf ...... 20.pdf, 21.pdf etc. .   

So I decide to add a prefix (ABC_0) to the filename. The new file name should be:

  abc_01.pdf, abc_02.pdf .... abc_10.pdf, abc_11.pdf ...... abc_20 pdf, abc191 pdf etc.   

So far everything is working fine. The problem is facing only that when a prefix is ​​added to a PDF file name with a number 10 and above, The name changes:

  ABC_010.pdf, ABC_011.pdf .... .. ABC_020.pdf, ABC_021.pdf etc.   

This is incorrect 0 should be paired with only 1 number in the PDF file names.

Can you help me?

This is the code with which I need help.

  {string dir = ttttsrc gttext (); String addPrefix = "ABC_0"; File directory, errorfile 1; File old file, new file; String newname; String filename []; Int i, count; DirFile = New File (DIR); If (Dirfile.exists () ||! DirFile.isDirectory ()) {Message ("File does not exist or does not have directory"); } File name = dirFile.list (); For (i = count = 0; i    

You can make sure that your filenames are null:

  public string pad (string filename, int lane) {if (fileName.length ()> gt0 = len) {return fileName;} string pad = "0000000" + fileName; // Change the number of zeros for your needs padded.substring (padded.length () - len);}   

Then you have to do "ABC_" for the padded value first:

  string newName = "A BC_ "+ Pad (old Newamam, 6); // output 6 characters per string   

generates such results:

  10.pdf gets ABC_10 .pdf 1.pdf gets ABC_01.pdf a.pdf becomes ABCGAPDF 100 PDF to ABBCIDADPDF AA ABC_ATHEAA    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -