Skip to content

Instantly share code, notes, and snippets.

@dtgay
Created May 9, 2012 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtgay/2647212 to your computer and use it in GitHub Desktop.
Save dtgay/2647212 to your computer and use it in GitHub Desktop.
Java won't append a slash if missing from a String
/**
* Tests the duplicate file finder
* For RIT 4002-219
* Author: David Gay
* Spring 2012
* CODE WRITTEN FOR USE ON A LINUX FILESYSTEM
*/
public class TestDups
{
/**
* Main
* Program entry point
* @param args[0] the starting directory
*/
public static void main(String[] args)
{
String startingDir;
try
{
startingDir = args[0];
System.out.println("last char: " + startingDir.charAt(startingDir.length() - 1));
if (startingDir.charAt(startingDir.length() - 1) != '/')
{
// If the user did not include a closing slash (/), append it
startingDir.concat("/");
}
}
catch (ArrayIndexOutOfBoundsException aioobe)
{
// If no argument is given, set a default starting dir
startingDir = "~/.";
}
System.out.println("Duplicate File Finder - by David Gay");
System.out.println("Find duplicates. Processing: " + startingDir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment