From 7f1d5c90d6a6587e588bdbd312ee036ad7b693ec Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 29 Oct 2009 10:10:22 +0000 Subject: [PATCH] added method for writing text to files --- .../java/se/sics/cooja/util/StringUtils.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/util/StringUtils.java b/tools/cooja/java/se/sics/cooja/util/StringUtils.java index 41688c1b6..835289e61 100644 --- a/tools/cooja/java/se/sics/cooja/util/StringUtils.java +++ b/tools/cooja/java/se/sics/cooja/util/StringUtils.java @@ -24,21 +24,23 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: StringUtils.java,v 1.2 2009/06/09 09:42:01 fros4943 Exp $ + * $Id: StringUtils.java,v 1.3 2009/10/29 10:10:22 fros4943 Exp $ */ package se.sics.cooja.util; import java.io.File; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintWriter; import java.net.URL; /** * Some utility methods for generating hex dumps. * - * @author Niclas Finne + * @author Niclas Finne, Fredrik Osterlind */ public class StringUtils { @@ -152,4 +154,15 @@ public class StringUtils { return null; } } + + public static boolean saveToFile(File file, String text) { + try { + PrintWriter outStream = new PrintWriter(new FileWriter(file)); + outStream.print(text); + outStream.close(); + return true; + } catch (Exception ex) { + return false; + } + } }