public static void logException(Exception ex) { try { ex.printStackTrace(); FileConnection log = (FileConnection) Connector.open("file://" + System.currentTimeMillis() + ".txt"); log.create(); OutputStream logstream = log.openOutputStream(); PrintStream logger = new PrintStream(logstream); logger.println(ex.getMessage()); logger.println(ex.toString()); logger.close(); logstream.close(); } catch (Exception ex2) { ex2.printStackTrace(); } }
// WRITE AS LITTLE AS POSSIBLE, CONSTANT WRITING(every tick) IS BAD FOR CRIO private void write(String path, byte[] data) { if (path == null) { path = DEFAULT_FILE_PATH; } synchronized (FileLock) { FileLock.notifyAll(); } FileConnection File = null; try { File = (FileConnection) Connector.open(path, Connector.READ_WRITE); if (File.exists()) { File.delete(); } File.create(); OutputStream output = File.openOutputStream(); if (data != null) { output.write(data); System.out.println("WRITING"); } } catch (IOException ex) { ex.printStackTrace(); } finally { if (File != null) { try { File.close(); System.out.println("WRITING COMPLETED"); } catch (IOException ex) { } } } }