/// <summary> /// インスタンスをテキストファイルに出力します /// </summary> /// <param name="sw">出力先</param> public void print(StreamWriter sw) throws IOException { String result = this.toString(); sw.writeLine(result); }
/** * Performs file compression into a certain file or directory and have it inside the specified * destination file path. * * @param forarchive Directory or file to compress * @param destination Output file destination. * @return File information of the output file. */ public java.io.File archive(java.io.File forarchive, String destination) { java.io.File _file = null; String _batchfilename = Application.startUpPath() + "\\archiver.bat"; String _zip = mime.Mime.resources.sevenZip().getPath(); if (_zip.startsWith("/")) _zip = mime.Mime.resources.sevenZip().getPath().substring(1); String _path = forarchive.getPath(); if (_path.startsWith("/")) _path = forarchive.getPath().substring(1); String _contents = "\"" + _zip + "\" a \"" + destination + "\" " + _path + "\""; java.io.File _batchfile = null; StreamWriter _sw = new StreamWriter(_batchfilename); try { _sw.write(_contents); _batchfile = new java.io.File(_batchfilename); } catch (Exception ex) { _batchfile = null; ex.printStackTrace(); } finally { _sw.close(); _sw.dispose(); } if (_batchfile != null) { java.lang.Process p = null; try { p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", _batchfilename}); p.waitFor(); InputStream _errorstream = p.getErrorStream(); String _error = ""; if (_errorstream != null) { int _bytecount = _errorstream.available(); if (_bytecount > 0) { StringWriter _writer = new StringWriter(); try { byte[] _bytes = new byte[_bytecount]; _errorstream.read(_bytes); _error = new String(_bytes); } catch (Exception ex) { ex.printStackTrace(); } finally { _writer.close(); _writer = null; System.gc(); } } } _file = new java.io.File(destination); if (!_file.exists()) { _file = null; System.gc(); } } catch (Exception ex) { _file = null; ex.printStackTrace(); } finally { if (p != null) p.destroy(); p = null; System.gc(); } try { _batchfile.delete(); } catch (Exception ex) { } finally { _batchfile = null; System.gc(); } } return _file; }