Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // No description, too long to write out
- JM Chapter 10 #17
- "1STFILE.TXT", "1STFILE.TXT"
- "HI:IamAllen", null
- "blah.blah.blah", null
- "HItherewhereareyou", null
- "1STFILE", "1STFILE.TXT"
- "1stFile", "1STFILE.TXT"
- "1stfile.", "1STFILE"
- "1STFILE.L", "1STFILE.L"
- "1STFILE.l", "1STFILE.l"
- "hello!?.txt", null
- "h.ello!.txt", "null"
- "hello!.jpeg", "null"
- "\\hello", "null"
- private String validFileName(String fileName) {
- if (fileName.length() > 11) {
- return null;
- }
- // There are more than two dots in the fileName or the extension is too
- // long
- if (fileName.indexOf(".") != -1 && (fileName.indexOf(".") != fileName.lastIndexOf(".")
- || (fileName.length() - fileName.lastIndexOf(".") > 4))) {
- return null;
- }
- // Check that there are no illegal characters, "." was checked for
- // before
- if (fileName.contains(":") || fileName.contains("\\")
- || fileName.contains("?") || fileName.contains("*")) {
- return null;
- }
- if (fileName.indexOf(".") == fileName.length() - 1) {
- return fileName.toUpperCase().substring(0, fileName.length() - 1);
- }
- if (fileName.indexOf(".") == -1) {
- return fileName.toUpperCase() + ".TXT";
- }
- return fileName.substring(0, fileName.indexOf(".")).toUpperCase()
- + fileName.substring(fileName.indexOf("."));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement