List of usage examples for java.io FileWriter FileWriter
public FileWriter(FileDescriptor fd)
From source file:bammerbom.ultimatecore.bukkit.resources.classes.ErrorLogger.java
public static void log(Throwable t, String s) { String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(Calendar.getInstance().getTime()); File dir = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors"); if (!dir.exists()) { dir.mkdir();//from w w w .java2 s . c om } File file = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors", time + ".txt"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } FileWriter outFile; try { outFile = new FileWriter(file); } catch (IOException e) { e.printStackTrace(); return; } PrintWriter out = new PrintWriter(outFile); out.println("======================================="); out.println("UltimateCore has run into an error "); out.println("Please report your error on dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket"); out.println("Bukkit version: " + Bukkit.getServer().getVersion()); out.println("UltimateCore version: " + r.getUC().getDescription().getVersion()); out.println("Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins())); out.println("Java version: " + System.getProperty("java.version")); out.println("OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version")); out.println("Time: " + time); out.println("Error message: " + t.getMessage()); out.println("UltimateCore message: " + s); out.println("======================================="); out.println("Stacktrace: \n" + ExceptionUtils.getStackTrace(t)); out.println("======================================="); out.close(); try { outFile.close(); } catch (IOException e) { e.printStackTrace(); } // Bukkit.getConsoleSender().sendMessage(" "); r.log(ChatColor.DARK_RED + "========================================================="); r.log(ChatColor.RED + "UltimateCore has run into an error "); r.log(ChatColor.RED + "Please report your error on "); r.log(ChatColor.YELLOW + "http://dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket"); r.log(ChatColor.RED + "Include the file: "); r.log(ChatColor.YELLOW + "plugins/UltimateCore/Errors/" + time + ".txt "); /*r.log(ChatColor.RED + "Bukkit version: " + Bukkit.getServer().getVersion()); r.log(ChatColor.RED + "UltimateCore version: " + Bukkit.getPluginManager().getPlugin("UltimateCore").getDescription().getVersion()); r.log(ChatColor.RED + "Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins())); r.log(ChatColor.RED + "Java version: " + System.getProperty("java.version")); r.log(ChatColor.RED + "OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version")); r.log(ChatColor.RED + "Error message: " + t.getMessage()); r.log(ChatColor.RED + "UltimateCore message: " + s);*/ r.log(ChatColor.DARK_RED + "========================================================="); if (t instanceof Exception) { r.log(ChatColor.RED + "Stacktrace: "); t.printStackTrace(); r.log(ChatColor.DARK_RED + "========================================================="); } Bukkit.getConsoleSender().sendMessage(" "); }
From source file:hsa.awp.common.dao.template.TemplateFileSystemDao.java
@Override public void saveTemplate(String content, TemplateDetail templateDetail) { try {/* w w w. j a v a 2 s . c o m*/ File file = new File(generatePath(templateDetail)); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.erdfelt.android.sdkfido.project.FilteredFileUtil.java
public static void copyWithExpansion(String resourceId, File destFile, Map<String, String> props) { URL url = FilteredFileUtil.class.getResource(resourceId); if (url == null) { LOG.log(Level.WARNING, "Unable to find resourceID: " + resourceId); return;/*from ww w . j a va 2 s . c om*/ } InputStream in = null; InputStreamReader reader = null; BufferedReader buf = null; FileWriter writer = null; PrintWriter out = null; try { in = url.openStream(); reader = new InputStreamReader(in); buf = new BufferedReader(reader); writer = new FileWriter(destFile); out = new PrintWriter(writer); PropertyExpander expander = new PropertyExpander(props); String line; while ((line = buf.readLine()) != null) { out.println(expander.expand(line)); } } catch (IOException e) { LOG.log(Level.WARNING, "Unable to open input stream for url: " + url, e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(writer); IOUtils.closeQuietly(buf); IOUtils.closeQuietly(reader); IOUtils.closeQuietly(in); } }
From source file:mx.com.pixup.portal.dao.ArtistaGenerateDaoJdbc.java
public ArtistaGenerateDaoJdbc() throws IOException { BasicDataSource dataSource = new BasicDataSource(); //seccion de la DB dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("admin"); //dataSource.setPassword("mysqlroot"); dataSource.setUrl("jdbc:mysql://localhost:3306/pixup"); this.dataSource = dataSource; //seccion XML this.xmlLogico = new Document(); this.xmlFisico = new XMLOutputter(); this.archivoFisico = new FileWriter( "C:\\Users\\JAVA-08\\Documents\\VOSS\\Modulo 5\\pixup-dao-xml\\src\\testXML\\artistasNuevo.xml"); }
From source file:mx.com.pixup.portal.dao.MunicipioGenerateDaoJdbc.java
public MunicipioGenerateDaoJdbc() throws IOException { BasicDataSource dataSource = new BasicDataSource(); //seccion de la DB dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("admin"); //dataSource.setPassword("mysqlroot"); dataSource.setUrl("jdbc:mysql://localhost:3306/pixup"); this.dataSource = dataSource; //seccion XML this.xmlLogico = new Document(); this.xmlFisico = new XMLOutputter(); this.archivoFisico = new FileWriter( "C:\\Users\\JAVA-08\\Documents\\VOSS\\Modulo 5\\pixup-dao-xml\\src\\testXML\\municipio1.xml"); }
From source file:test.gov.nih.nci.system.web.client.ProductUpdateClient.java
private static File marshall(Product product) throws IOException, XMLUtilityException { String namespacePrefix = "gme://caCORE.caCORE/3.2/"; String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetoone.bidirectional"; Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix); Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName); XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller); File myFile = new File("Product.xml"); FileWriter myWriter = new FileWriter(myFile); myUtil.toXML(product, myWriter);/*from ww w . j a v a2 s . c o m*/ myWriter.close(); return myFile; }
From source file:mn.EngineForge.module.player.java
public void saveRegisteration() throws IOException { JSONObject reg = new JSONObject(); reg.put("ID", id); reg.put("USERNAME", username); reg.put("PASSWORD", password); reg.put("REG_DATE", null); reg.put("LAST_LOGIN", null); reg.put("POSITION", null); /* JSON ARRAY NOTE// w w w . jav a2 s . com JSONArray company = new JSONArray(); company.add("Compnay: eBay"); company.add("Compnay: Paypal"); company.add("Compnay: Google"); reg.put("Company List", company); */ FileWriter file = new FileWriter(this.path); try { file.write(reg.toJSONString()); } catch (IOException e) { e.printStackTrace(); } finally { file.flush(); file.close(); } }
From source file:com.avatarproject.core.storage.UserCache.java
/** * Adds a player into the custom UserCache. * @param player Player to add to the cache. */// w w w .j a v a 2 s . com @SuppressWarnings("unchecked") public static void addUser(Player player) { String name = player.getName(); UUID uuid = player.getUniqueId(); JSONArray array = getUserCache(); try { for (int n = 0; n < array.size(); n++) { //Loop through all the objects in the array. JSONObject object = (JSONObject) array.get(n); if (object.get("id").equals(uuid.toString())) { //Check if the player's UUID exists in the cache. if (String.valueOf(object.get("name")).equalsIgnoreCase(name)) { return; } else { object.put("name", name); //Update the user. FileWriter fileOut = new FileWriter(usercache); fileOut.write(array.toJSONString()); //Write the JSON array to the file. fileOut.close(); return; } } } JSONObject newEntry = new JSONObject(); newEntry.put("id", uuid.toString()); newEntry.put("name", name); array.add(newEntry); //Add a new player into the cache. FileWriter fileOut = new FileWriter(usercache); fileOut.write(array.toJSONString()); //Write the JSON array to the file. fileOut.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.kircherelectronics.gyroscopeexplorer.datalogger.CsvDataLogger.java
public CsvDataLogger(Context context, File file) { this.context = context; this.file = file; CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator(System.getProperty("line.separator")); try {/*from w w w .ja v a2 s . c o m*/ fileWriter = new FileWriter(file); csv = new CSVPrinter(fileWriter, csvFileFormat); } catch (IOException e) { e.printStackTrace(); } headersSet = false; }
From source file:mx.com.pixup.portal.dao.DiscoPaisGenerateDaoJdbc.java
public DiscoPaisGenerateDaoJdbc(String archivo) throws IOException { BasicDataSource dataSource = new BasicDataSource(); //seccion de la DB dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("admin"); //dataSource.setPassword("mysqlroot"); dataSource.setUrl("jdbc:mysql://localhost:3306/pixup"); this.dataSource = dataSource; //seccion XML this.xmlLogico = new Document(); this.xmlFisico = new XMLOutputter(); this.archivoFisico = new FileWriter(archivo); }