List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:control.LoadControler.java
public static List<Geographie> loadGeographie(String filePath) { List<Geographie> list = new ArrayList<>(); File folder = new File(userPath(filePath)); Set<File> fileSet = listFilesForFolder(folder); for (File file : fileSet) { try {//from www. ja v a 2 s. c o m PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath()); Properties properties = ppr.readProperties(); try { Geographie element = new Geographie(); element.setNom(properties.getProperty("nom")); element.setImage(properties.getProperty("image")); element.setIsCombatable(Boolean.parseBoolean(properties.getProperty("isCombatable"))); element.setHandicapJ1Tir(Double.parseDouble(properties.getProperty("handicapJ1Tir"))); element.setHandicapJ2Tir(Double.parseDouble(properties.getProperty("handicapJ2Tir"))); list.add(element); System.out.println(element.toString()); //DEBUG } catch (NumberFormatException e) { e.printStackTrace(); System.out.println("##### Erreur lors de la cration d'une geographie #####"); JOptionPane.showMessageDialog(null, e); } } catch (IOException ex) { Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex); } } return list; }
From source file:io.github.azige.mages.Util.java
static List<Plugin> loadPluginsFromDirectory(File dir) { List<Plugin> list = new LinkedList<>(); File[] files = dir.listFiles(new FilenameFilter() { @Override/* ww w . j a v a 2 s. c o m*/ public boolean accept(File dir, String name) { return name.endsWith(".groovy"); } }); if (files == null) { return list; } try { GroovyClassLoader loader = new GroovyClassLoader(); loader.addClasspath(dir.getCanonicalPath()); final int extLength = ".groovy".length(); for (File f : files) { String name = f.getName(); String script = FileUtils.readFileToString(f, "UTF-8"); list.add(wrapPlugin(name.substring(0, name.length() - extLength), loader.parseClass(script).newInstance())); } } catch (Exception ex) { throw new MagesException(ex); } return list; }
From source file:control.LoadControler.java
public static List<Carte> loadCartes(String filePath) { File folder = new File(userPath(filePath)); Set<File> fileSet = listFilesForFolder(folder); List<Carte> list = new ArrayList<>(); for (File file : fileSet) { try {/*from w w w.j av a 2 s . co m*/ PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath()); Properties properties = ppr.readProperties(); Carte carte = new Carte(); try { carte.setNom(properties.getProperty("nom")); carte.setDx(Integer.parseInt(properties.getProperty("dx"))); carte.setDy(Integer.parseInt(properties.getProperty("dy"))); Properties ppts = new Properties(); ppts.putAll(properties); ppts.remove("nom"); ppts.remove("dx"); ppts.remove("dy"); carte.setProperties(ppts); System.out.println(carte.toString()); //DEBUG list.add(carte); } catch (NumberFormatException e) { e.printStackTrace(); System.out.println("##### Erreur lors de la cration de la carte #####"); JOptionPane.showMessageDialog(null, e); } } catch (IOException ex) { Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex); } } return list; }
From source file:control.LoadControler.java
public static Map<String, Integer> loadmainSettings(String filePath) { Map<String, Integer> list = new HashMap<>(); File file = new File(userPath(filePath)); try {//w w w .j a v a 2 s. c o m PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath()); Properties properties = ppr.readProperties(); try { Integer nbInitSoldatsParHeros = Integer.parseInt(properties.getProperty("nbInitSoldatsParHeros")); Integer xpInit = Integer.parseInt(properties.getProperty("xpInit")); Integer popNiveau10 = Integer.parseInt(properties.getProperty("popNiveau10")); list.put("nbInitSoldatsParHeros", nbInitSoldatsParHeros); list.put("xpInit", xpInit); list.put("popNiveau10", popNiveau10); System.out.println(list.toString()); //DEBUG } catch (NumberFormatException e) { e.printStackTrace(); System.out.println("##### Erreur lors de la lecture des paramtres gnraux #####"); JOptionPane.showMessageDialog(null, e); } } catch (IOException ex) { Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex); } return list; }
From source file:control.LoadControler.java
public static Map<String, List<String>> loadNoms(String filePath) { Map<String, List<String>> map = new HashMap<>(); File folder = new File(userPath(filePath)); Set<File> fileSet = listFilesForFolder(folder); for (File file : fileSet) { try {//from w ww . j a v a 2s .c o m CsvReader reader = new CsvReader(file.getCanonicalPath()); reader.readHeaders(); String[] headersTab = reader.getHeaders(); for (String header : headersTab) { map.put(header, new ArrayList<String>()); } while (reader.readRecord()) { for (String header : headersTab) { String value = reader.get(header); if (!value.isEmpty()) { map.get(header).add(value); } } } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e); } } // DEBUG for (String key : map.keySet()) { System.out.print(key + " : "); for (String value : map.get(key)) { System.out.print(value + " "); } System.out.println(); } return map; }
From source file:control.LoadControler.java
public static HashMap<String, Propriete> loadProprietes(String filePath) { File folder = new File(userPath(filePath)); Set<File> fileSet = listFilesForFolder(folder); HashMap<String, Propriete> proprieteMap = new HashMap<>(); for (File file : fileSet) { try {/* w w w. ja va 2 s .co m*/ PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath()); Properties properties = ppr.readProperties(); Propriete element = new Propriete(); try { String nom = new String(properties.getProperty("nom").getBytes("ISO-8859-1"), "UTF-8"); element.setType(properties.getProperty("type")); element.setNom(nom); element.setImage(properties.getProperty("image")); element.setCapaciteCombat(Double.parseDouble(properties.getProperty("capaciteCombat"))); element.setCapaciteTir(Double.parseDouble(properties.getProperty("capaciteTir"))); element.setCapaciteDeplacement( Double.parseDouble(properties.getProperty("capaciteDeplacement"))); String description = new String(properties.getProperty("description").getBytes("ISO-8859-1"), "UTF-8"); element.setDescription(description); proprieteMap.put(nom.toLowerCase(), element); System.out.println(element.toString()); //DEBUG } catch (NumberFormatException e) { e.printStackTrace(); System.out.println("##### Erreur lors de la cration d'une propriete #####"); JOptionPane.showMessageDialog(null, e); } } catch (IOException ex) { Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex); } } return proprieteMap; }
From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java
private static void addToCache(String cacheName, Game game) throws FileNotFoundException, UnsupportedEncodingException, IOException { logger.log(Level.FINEST, "Saving file {0} to cache", cacheName); File file = new File("archive.zip"); File file1 = null; if (file.exists()) { //copy to archive1, return file1 = new File("archive1.zip"); if (file1.exists()) { if (!file1.delete()) { logger.log(Level.WARNING, "Unable to delete file {0}", file1.getCanonicalPath()); return; }//from w ww . jav a2s . com } if (!file.renameTo(file1)) { logger.log(Level.WARNING, "Unable to rename file {0} to {1}", new Object[] { file.getCanonicalPath(), file1.getCanonicalPath() }); // unable to move to archive1 and whole operation fails!!! return; } } try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))) { out.setLevel(9); // name the file inside the zip file out.putNextEntry(new ZipEntry(cacheName)); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out, "UTF-8"); JsonWriter jsonWriter = new JsonWriter(outputStreamWriter); jsonWriter.setIndent(" "); builder.create().toJson(game, Game.class, jsonWriter); jsonWriter.flush(); if (file1 != null) { try (ZipFile zipFile = new ZipFile(file1)) { Enumeration<? extends ZipEntry> files = zipFile.entries(); while (files.hasMoreElements()) { ZipEntry entry = files.nextElement(); try (InputStream in = zipFile.getInputStream(entry)) { out.putNextEntry(new ZipEntry(entry.getName())); IOUtils.copy(in, out); } } } file1.delete(); } } }
From source file:com.maomao.server.AppManager.java
/** * parse app.xml//from w w w . j a v a 2 s . c o m * * @param file * @throws Exception */ public static void parseAppModeXml(App app, File file) throws Exception { logger.info("reading app.xml in app docbase:" + file.getPath()); URL url = null; if (file.isFile() && file.getName().endsWith(".jar")) { String appConfig = "jar:file:" + file.getCanonicalPath() + "!/" + appXml; url = new URL(appConfig); } else if (file.isDirectory()) { File confFile = new File(file, "app.xml"); if (!confFile.exists()) { throw new Exception("Cannot find app.xml in : " + file.getCanonicalPath()); } url = confFile.toURI().toURL(); } if (url != null) { XStream xs = new XStream(); xs.alias("mm-app", App.class); App appDesc = (App) xs.fromXML(url.openStream()); // merge app.setPk(appDesc.getPk()); app.setAppid(appDesc.getAppid()); app.setName(appDesc.getName()); app.setDescription(appDesc.getDescription()); app.setEmail(appDesc.getEmail()); app.setDeveloper(appDesc.getDeveloper()); app.setVersion(appDesc.getVersion()); app.setVersionLabel(appDesc.getVersionLabel()); } }
From source file:net.semanticmetadata.lire.utils.FileUtils.java
/** * Returns all images from a directory in an array. Image files are identified by their suffix being from {.png, .jpg, .jpeg, .gif} in case insensitive manner. * * @param directory the directory to start with * @param descendIntoSubDirectories should we include sub directories? * @return an ArrayList<String> containing all the files or null if none are found.. * @throws IOException/*w w w . jav a 2 s. c om*/ */ public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories) throws IOException { ArrayList<String> resultList = new ArrayList<String>(256); IOFileFilter includeSubdirectories = TrueFileFilter.INSTANCE; if (!descendIntoSubDirectories) includeSubdirectories = null; Iterator<File> fileIterator = org.apache.commons.io.FileUtils.iterateFiles(directory, fileFilter, includeSubdirectories); while (fileIterator.hasNext()) { File next = fileIterator.next(); resultList.add(next.getCanonicalPath()); } if (resultList.size() > 0) return resultList; else return null; }
From source file:ffx.autoparm.Keyword_poltype.java
/** * This method sets up configuration properties in the following precedence * order: 1.) Java system properties a.) -Dkey=value from the Java command * line b.) System.setProperty("key","value") within Java code. * * 2.) Structure specific properties (for example pdbname.properties) * * 3.) User specific properties (~/.ffx/ffx.properties) * * 4.) System wide properties (file defined by environment variable * FFX_PROPERTIES)//from w w w . j a v a 2s. c o m * * 5.) Internal force field definition. * * @since 1.0 * @param file a {@link java.io.File} object. * @return a {@link org.apache.commons.configuration.CompositeConfiguration} * object. */ public static CompositeConfiguration loadProperties(File file) { /** * Command line options take precedences. */ CompositeConfiguration properties = new CompositeConfiguration(); properties.addConfiguration(new SystemConfiguration()); /** * Structure specific options are 2nd. */ if (file != null && file.exists() && file.canRead()) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String prmfilename = br.readLine().split(" +")[1]; File prmfile = new File(prmfilename); if (prmfile.exists() && prmfile.canRead()) { properties.addConfiguration(new PropertiesConfiguration(prmfile)); properties.addProperty("propertyFile", prmfile.getCanonicalPath()); } } catch (Exception e1) { e1.printStackTrace(); } } // /** // * User specific options are 3rd. // */ // String filename = System.getProperty("user.home") + File.separator // + ".ffx/ffx.properties"; // File userPropFile = new File(filename); // if (userPropFile.exists() && userPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // userPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // // /** // * System wide options are 2nd to last. // */ // filename = System.getenv("FFX_PROPERTIES"); // if (filename != null) { // File systemPropFile = new File(filename); // if (systemPropFile.exists() && systemPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // systemPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // } /** * Echo the interpolated configuration. */ if (logger.isLoggable(Level.FINE)) { Configuration config = properties.interpolatedConfiguration(); Iterator<String> i = config.getKeys(); while (i.hasNext()) { String s = i.next(); logger.fine("Key: " + s + ", Value: " + Arrays.toString(config.getList(s).toArray())); } } return properties; }