From 133eaad50d2a868774e1d7f0114c01ea49a0f0c6 Mon Sep 17 00:00:00 2001 From: hansen <dominik_hansen@web.de> Date: Mon, 5 May 2014 21:00:18 +0200 Subject: [PATCH] added missing class --- src/main/java/de/tla2b/util/FileUtils.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/de/tla2b/util/FileUtils.java diff --git a/src/main/java/de/tla2b/util/FileUtils.java b/src/main/java/de/tla2b/util/FileUtils.java new file mode 100644 index 0000000..374560f --- /dev/null +++ b/src/main/java/de/tla2b/util/FileUtils.java @@ -0,0 +1,46 @@ +package de.tla2b.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class FileUtils { + + public static String removeExtention(String filePath) { + File f = new File(filePath); + + // if it's a directory, don't remove the extention + if (f.isDirectory()) + return filePath; + + String name = f.getName(); + + // Now we know it's a file - don't need to do any special hidden + // checking or contains() checking because of: + final int lastPeriodPos = name.lastIndexOf('.'); + if (lastPeriodPos <= 0) { + // No period after first character - return name as it was passed in + return filePath; + } else { + // Remove the last period and everything after it + File renamed = new File(f.getParent(), name.substring(0, + lastPeriodPos)); + return renamed.getPath(); + } + } + + public static String fileToString(String fileName) throws IOException { + StringBuilder res = new StringBuilder(); + BufferedReader in = new BufferedReader(new FileReader(fileName)); + String str; + while ((str = in.readLine()) != null) { + res.append(str + "\n"); + } + in.close(); + return res.toString(); + } + + + +} -- GitLab