0

I've been trying to write a programm that looks for .cbr files in special directory and makes them look just as I need.

When I see chars and strings in the input console (I was checking everything, I thought that problem was with something else) everything looks fine, so I think problem with File.renameTo

No matter what my input is, in the end I have(if those files were .cbr) something like [C@2d363fb3 (real example) Here's my code:

import java.io.File;
import java.io.IOException;

public class CBR_Manager {
  public static void main(String[] argv) throws IOException {
    File folder = new File("\\Users\\Admin\\Desktop\\For comics managing");
    File[] listOfFiles = folder.listFiles();
    boolean b;

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile()) {
        File f = new File("C:\\Users\\Admin\\Desktop\\For comics managing\\" + listOfFiles[i].getName());
        int j = 0; b = false;
        String name = f.getName();
        if (name.endsWith(".cbr")) {
          char[] Name = new char[100];
          name.toCharArray();
          System.out.println(name);
          while ((b != true) || (j + 4 < name.length())) {
            if ((b == false) && (Character.isDigit(name.charAt(j))) && (Character.isDigit(name.charAt(j + 1))) && (!Character.isDigit(name.charAt(j + 2)))) {
              for (int k = 0; k < j; k++) {
                Name[k] = name.charAt(k);
              }
              Name[j] = '0';
              Name[j + 1] = name.charAt(j);
              Name[j + 2] = name.charAt(j + 1);
              Name[j + 3] = '.';
              Name[j + 4] = 'c';
              Name[j + 5] = 'b';
              Name[j + 6] = 'r';
              b = true;
              for (int l=0; l<j+7; l++) {
                System.out.println(Name[l]);
              }
              int EndOfNewCBRIncluded = j + 6;
              int OldIncludedDeleteEdge = j + 2;
              int NewIncludedDeleteEdge = j + 3;
            } else if ((b == false) && (Character.isDigit(name.charAt(j))) && (!Character.isDigit(name.charAt(j + 1))) && (!Character.isDigit(name.charAt(j + 2)))) {
              for (int k = 0; k < j; k++) {
                Name[k] = name.charAt(k);
              }
              Name[j] = Name[j + 1] = '0';
              Name[j + 2] = name.charAt(j);
              Name[j + 3] = '.';
              Name[j + 4] = 'c';
              Name[j + 5] = 'b';
              Name[j + 6] = 'r';
              b = true;
              for (int l=0; l<j+7; l++) {
                System.out.println(Name[l]);
              }
              int EndOfNewCBRIncluded = j + 6;
              int OldIncludedDeleteEdge = j + 1;
              int NewIncludedDeleteEdge = j + 3;
            } else if ((b == false) && (Character.isDigit(name.charAt(j))) && (Character.isDigit(name.charAt(j + 1))) && (Character.isDigit(name.charAt(j + 2)))) {
              for (int k = 0; k < j + 3; k++) {
                Name[k] = name.charAt(k);
              }
              Name[j + 3] = '.';
              Name[j + 4] = 'c';
              Name[j + 5] = 'b';
              Name[j + 6] = 'r';
              b = true;
              for (int l=0; l<j+7; l++) {
                System.out.println(Name[l]);
              }
              int EndOfNewCBRIncluded = j + 6;
              int OldIncludedDeleteEdge = j + 3;
              int NewIncludedDeleteEdge = j + 3;
            }
            j++;
            //(name.charAt(j) != '.') &&(name.charAt(j + 1) != 'c') && (name.charAt(j + 2) != 'b') && (name.charAt(j + 3) != 'r')
          }
          f.renameTo(new File("C:\\Users\\Admin\\Desktop\\For comics managing\\" + Name));
        }
      }

      System.out.println("conversion is done");
    }
  }
}

What should I do? It's my second programming week, I hope my code isn't so disturbing

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
  • 1
    Possible duplicate of [What's the simplest way to print a Java array?](http://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array) – bradimus Nov 01 '16 at 20:09
  • 2
    What bradimus commented, and: you should really take a look at [String](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html) and [StringBuilder](http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html) – BackSlash Nov 01 '16 at 20:10

1 Answers1

0

As bradimus and BackSlash hinted, you are using char[] when you probably should be using String or StringBuilder, but with that being said, you are trying to print out your char[] which just prints the reference ID. Try this instead:

f.renameTo(new File("C:\\Users\\Admin\\Desktop\\For comics managing\\" + String.valueOf(Name).trim()));
bcampolo
  • 593
  • 5
  • 12