これは、提供されたヒントのいくつかを使用して実装した方法です。最初に、3桁のセットの配列でインデックスを分解する関数:
private static void decompose(final long l, final short[] array) {
long q = l;
long r = 0;
for (int j=array.length-1; j >= 0; j--) {
// compute remainder
r = q % 1000;
// compute quotient
// converts to int and fractional part is dropped without rounding
q = q / 1000;
array[j] = (short) r;
}
}
次に、分解された配列(currentA)を使用して、サブディレクトリとファイルオブジェクトを作成します。
File dir = parent;
for (int j=0; j < depth-1; j++) {
String dirName = String.format("%03d", currentA[j]);
dir = new File(dir, dirName);
}
String fileName = prefix + String.format("%03d", currentA[depth]) + suffix;
File file = new File(dir, fileName);