public static long[] getScaledFileSizesMB(File dir, long totalDesiredSize, String... fileNames) throws IOException {

		if (!dir.exists() || !dir.isDirectory()) {
			throw new IOException("The directory does not exist or is not a directory: " + dir.getAbsolutePath());
		}


		// Get the files

		File[] files = new File[fileNames.length];
		for (int i = 0; i < fileNames.length; i++) {
			File f = new File(dir, fileNames[i]);
			if (!f.exists() || !f.isFile()) {
				throw new IOException("The following file does not exist or is not a regular file: " + f.getName());
			}
			files[i] = f;
		}



		// Get the size of the files

		long[] sizes = new long[files.length];
		long total = 0;
		for (int i = 0; i < sizes.length; i++) {
			sizes[i] = Math.round(Math.ceil(files[i].length() / 1048576.0));
			total += sizes[i];
		}


		// Scale the size of the files

		double f = totalDesiredSize / (double) total;
		long[] adjusted = new long[sizes.length];
		for (int i = 0; i < sizes.length; i++) {
			adjusted[i] = Math.round(sizes[i] * f);
			if (adjusted[i] < 1) adjusted[i] = 1;
		}

		return adjusted;
	}