Storypost | 2016.03.16
|
The .11 line is notorious for this problem, especially the 1.5TB version. The only HDDs I've had ever problems with were Seagate drives, and both were .11 drives. My issue was different - very high error counts which caused very poor performance from sector reallocation. That whole line was very problematic. |
package file_copy; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Random; public class Main { public static void main(String args[]) { String dir = "[dir name]"; StringBuffer log = new StringBuffer(); // Define file locations. File destination_super = new File("[new dir]"); File source_super = new File("[old dir]"); File destination = new File(destination_super, dir); File source = new File(source_super, dir); if (!destination.exists()) { destination.mkdir(); } File last_file = null; int count = 0; // Keep track of files copied. int fails = 0; // Let a few failures occur before bailing. try { if (source.exists()) { // Randomize the files in the directory, this will avoid hitting // bad sectors repeatedly. Random random = new Random(); log.append("Running: " + source.getAbsolutePath() + " " + source.listFiles().length + " files\n"); List<File> files = new ArrayList<File>(); for (File file : source.listFiles()) { if (files.size() == 0) { files.add(file); } else { files.add(random.nextInt(files.size()), file); } } // Walk the randomized file list. for (File file : files) { File target = new File(destination, file.getName()); // Don't try to go deep, just inform user of a subdirectory. if (file.isDirectory()) { log.append("Skipped subdirectory: " + file.getAbsolutePath() + "\n"); } last_file = target; if (!target.exists()) { try { count++; Files.copy(Paths.get(file.getAbsolutePath()), Paths.get(target.getAbsolutePath())); } catch (Exception e) { log.append("Failed on " + last_file.getAbsolutePath() + "\n"); fails++; if (fails > 7) { throw e; } } } } log.append("Finished " + source.getAbsolutePath() + " " + source.listFiles().length + " files\n"); } else { log.append("Could not find: " + source.getAbsolutePath()); } } catch (Exception e) { log.append("Failed on " + last_file + " " + count + " completed\n"); log.append(e.getMessage()); } try { PrintWriter writer = new PrintWriter( new FileOutputStream(new File("C:\\data\\output.txt"))); writer.write(log.toString()); writer.close(); System.exit(0); } catch (Exception e) { System.exit(1); } } }
Don't die! |
◄ |
2016.03.02
SedentaryMCL tear, froading, clay pigeons, volleyball. |
2016.04.03
All gamesThe Division, Broforce, and Helldivers |
► |
2016.04.03
All gamesThe Division, Broforce, and Helldivers |
2020.02.11
WhistlerA ski trip to Whistler. |
2016.02.20
Moving earthA motorsports fan judges Monster Jam (and gets booed). Cities: Skylines, Helldivers, and Fallout 4. |
twilweb.wordpress.com
SimpleDateFormatter is not thread-safe - twilwebHaving been bitten by this bug multiple times, i am posting a small program that illustrates Thread Safety issues in using SimpleDateFormatter from java . import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.conc... |
jamesward.com
Java Concurrency with Akka: Composing Futures - James Ward |
studiofreya.org
Java Basic Programs: 5 Simple Examples - Studiofreya SSG Site |