Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1051 | chris | 1 | package com.gebauz.bauzoid.file; |
| 2 | |||
| 3 | /** File utilities and convenience functions. */ |
||
| 4 | public class FileUtil |
||
| 5 | { |
||
| 6 | private FileUtil() {} |
||
| 7 | |||
| 8 | /** Extract the filename's path. */ |
||
| 9 | public static String extractPath(String filename) |
||
| 10 | { |
||
| 11 | for (int n = filename.length()-1; n >= 0; n--) |
||
| 12 | { |
||
| 13 | if ((filename.charAt(n) == '\\') || |
||
| 14 | (filename.charAt(n) == '/')) |
||
| 15 | { |
||
| 16 | return filename.substring(0, n); |
||
| 17 | } |
||
| 18 | } |
||
| 19 | |||
| 20 | return filename; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** Extract the path's filename including its extension. */ |
||
| 24 | public static String extractFilename(String filePath) |
||
| 25 | { |
||
| 26 | for (int n = filePath.length()-1; n >= 0; n--) |
||
| 27 | { |
||
| 28 | if ((filePath.charAt(n) == '\\') || |
||
| 29 | (filePath.charAt(n) == '/')) |
||
| 30 | { |
||
| 31 | return filePath.substring(n+1, filePath.length()); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | return filePath; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** Extract the path's filename without its extension. */ |
||
| 38 | public static String extractFilenameNoExt(String filePath) |
||
| 39 | { |
||
| 40 | for (int n = filePath.length()-1; n >= 0; n--) |
||
| 41 | { |
||
| 42 | if (filePath.charAt(n) == '.') |
||
| 43 | { |
||
| 44 | return extractFilename(filePath.substring(0, n)); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | return filePath; |
||
| 48 | } |
||
| 49 | |||
| 50 | /* public static String loadString(FileHandle handle) |
||
| 51 | { |
||
| 52 | return handle.readString(); |
||
| 53 | }*/ |
||
| 54 | |||
| 55 | /** Load a file into a string from assets. */ |
||
| 56 | /* public static String loadStringFromAsset(Resources resources, String asset) throws IOException |
||
| 57 | { |
||
| 58 | InputStream is = resources.getAssets().open(asset); |
||
| 59 | |||
| 60 | return loadString(is); |
||
| 61 | }*/ |
||
| 62 | |||
| 63 | /** Load a file into a string from resources. */ |
||
| 64 | /* public static String loadStringFromResource(Resources resources, int id) throws IOException |
||
| 65 | { |
||
| 66 | InputStream is = resources.openRawResource(id); |
||
| 67 | |||
| 68 | return loadString(is); |
||
| 69 | }*/ |
||
| 70 | |||
| 71 | /* public static String loadString(InputStream is) throws IOException |
||
| 72 | { |
||
| 73 | byte[] buffer = new byte[is.available()]; |
||
| 74 | is.read(buffer); |
||
| 75 | |||
| 76 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
| 77 | os.write(buffer); |
||
| 78 | os.close(); |
||
| 79 | |||
| 80 | is.close(); |
||
| 81 | |||
| 82 | return os.toString(); |
||
| 83 | }*/ |
||
| 84 | |||
| 85 | /** Load a file from assets. */ |
||
| 86 | /* public static File loadFileFromAsset(Resources resources, String asset) throws IOException |
||
| 87 | { |
||
| 88 | InputStream is = resources.getAssets().open(asset); |
||
| 89 | return new File(is); |
||
| 90 | }*/ |
||
| 91 | |||
| 92 | /** Load a file from resources. */ |
||
| 93 | /* public static File loadFileFromResource(Resources resources, int id) throws IOException |
||
| 94 | { |
||
| 95 | InputStream is = resources.openRawResource(id); |
||
| 96 | return new File(is); |
||
| 97 | }*/ |
||
| 98 | } |
||
| 99 |