List of usage examples for java.io File getPath
public String getPath()
From source file:atg.tools.dynunit.test.util.FileUtil.java
private static void setConfigFileLastModified(final File configFile) { Validate.notNull(configFile);//from w w w . ja va 2s . c o m setConfigFileLastModified(configFile.getPath(), configFile.lastModified()); }
From source file:net.sf.taverna.t2.maven.plugins.Utils.java
public static String uploadFile(File file, String resourceName, Wagon wagon, Log log) throws MojoExecutionException { String resourceUrl = getResourceUrl(wagon, resourceName); File digestFile = new File(file.getPath() + ".md5"); try {//from w ww. j a va 2 s . co m String digestString = DigestUtils.md5Hex(new FileInputStream(file)); FileUtils.writeStringToFile(digestFile, digestString); } catch (IOException e) { throw new MojoExecutionException(String.format("Error generating digest for %1$s", file), e); } try { log.info(String.format("Uploading %1$s to %2$s", file, resourceUrl)); wagon.put(file, resourceName); wagon.put(digestFile, resourceName + ".md5"); } catch (TransferFailedException e) { throw new MojoExecutionException(String.format("Error transferring %1$s to %2$s", file, resourceUrl), e); } catch (ResourceDoesNotExistException e) { throw new MojoExecutionException(String.format("%1$s does not exist", resourceUrl), e); } catch (AuthorizationException e) { throw new MojoExecutionException( String.format("Authentication error transferring %1$s to %2$s", file, resourceUrl), e); } return resourceUrl; }
From source file:com.guye.baffle.util.OS.java
public static void cpdir(File src, File dest) throws BaffleException { dest.mkdirs();/* w w w . j a v a 2 s . co m*/ File[] files = src.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; File destFile = new File(dest.getPath() + File.separatorChar + file.getName()); if (file.isDirectory()) { cpdir(file, destFile); continue; } try { InputStream in = new FileInputStream(file); OutputStream out = new FileOutputStream(destFile); IOUtils.copy(in, out); in.close(); out.close(); } catch (IOException ex) { throw new BaffleException("Could not copy file: " + file, ex); } } }
From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java
private static JButton createBrowseButton(final boolean directoriesOnly, final String browserApproveButtonText, final JTextField textField, final FileFilter... fileFilters) { JButton browseButton = new JButton("..."); browseButton.addActionListener(new ActionListener() { @Override/*from w w w .j av a 2 s . co m*/ public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (textField.getText() != null) { File file = new File(textField.getText()); // if the file doesn't exist but the directory does, get that if (!file.exists() && file.getParentFile() != null && file.getParentFile().exists()) { file = file.getParentFile(); } if (!directoriesOnly && file.isFile()) { chooser.setSelectedFile(file); } if (file.isDirectory() && file.exists()) { chooser.setCurrentDirectory(file); } } if (directoriesOnly) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } // add filters and automatically select correct one if (fileFilters.length == 1) { chooser.setFileFilter(fileFilters[0]); } else { for (FileFilter filter : fileFilters) { chooser.addChoosableFileFilter(filter); if (filter instanceof FileNameExtensionFilter) { if (matchesFilter((FileNameExtensionFilter) filter, textField.getText())) { chooser.setFileFilter(filter); } } } } if (chooser.showDialog(textField, browserApproveButtonText) == JFileChooser.APPROVE_OPTION) { //File selected = processSelectedFile(chooser.getSelectedFile()); File selected = chooser.getSelectedFile(); String path = selected.getPath(); FileFilter filter = chooser.getFileFilter(); if (filter != null && filter instanceof FileNameExtensionFilter) { boolean found = matchesFilter(((FileNameExtensionFilter) chooser.getFileFilter()), path); if (!found) { String[] exts = ((FileNameExtensionFilter) chooser.getFileFilter()).getExtensions(); if (exts.length > 0) { path = FilenameUtils.removeExtension(path); path += "." + exts[0]; } } } textField.setText(path); } } }); return browseButton; }
From source file:de.dakror.virtualhub.server.DBManager.java
public static Eticet eticet(File f, String catalog, Eticet e) { try {/*from w ww . j a va 2 s . co m*/ if (e == Eticet.NULL) { ResultSet rs = connection.createStatement() .executeQuery("SELECT ETICET FROM ETICETS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); if (!rs.next()) return Eticet.NONE; return Eticet.values()[rs.getInt(1)]; } else { if (e == Eticet.NONE) connection.createStatement().executeUpdate("DELETE FROM ETICETS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); else connection.createStatement().executeUpdate( "INSERT OR REPLACE INTO ETICETS VALUES(\"" + f.getPath().replace("\\", "/") + "\"," + e.ordinal() + ") AND CATALOG = \"" + catalog + "\""); } } catch (SQLException e1) { e1.printStackTrace(); } return null; }
From source file:net.menthor.editor.v2.util.Util.java
/** * Inspects the name of the specified file and checks if it ends with the * specified suffix. If not, a new file will be created, appending the suffix * to the file name, otherwise the original file object will be returned. *///from w ww . j a v a2 s .c om public static File getFileWithExtension(File file, String extension) { String path = file.getPath(); File result = file; Pattern pattern = Pattern.compile(".*\\" + extension); if (!pattern.matcher(path).matches()) { path = path + extension; result = new File(path); } return result; }
From source file:com.huawei.streaming.cql.CQLTestCommons.java
/** * /*ww w . j a v a 2 s.co m*/ * * @param f * @param values * @throws IOException ? */ public static void appendToFile(File f, String values) throws IOException { if (!f.exists()) { if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } LOG.warn("file " + f.getPath() + " does not exist! will create it."); if (!f.createNewFile()) { LOG.error("failed to create file " + f.getPath()); return; } } if (f.isDirectory()) { LOG.error("file " + f.getPath() + " is a directory!"); } FileUtils.write(f, values, CHARSET, true); }
From source file:com.ecofactor.qa.automation.platform.util.SeleniumDriverUtil.java
/** * Creates the android driver.// ww w .j a v a 2 s. c om * @param deviceType the device type * @return the web driver * @throws DeviceException the device exception */ public static WebDriver createAndroidDriver(final boolean deviceType) throws DeviceException { if (!hasErrors) { try { setLogString(LogSection.START, deviceType ? "Uninstalling App" : "Installing App", true); final File app = getAppPath(); setLogString("App Location : " + app.getPath(), true); final DesiredCapabilities capabilities = setDriverCapabilities(deviceType, app); capabilities.setCapability(CapabilityType.BROWSER_NAME, getDeviceName()); setLogString("Launch webdriver", true); final WebDriver driver = new SwipeableWebDriver(new URL(createHostUrl()), capabilities); setLogString(LogSection.END, "App Process Completed", true); return driver; } catch (final Exception ex) { checkIfAppiumError(ex); } } return null; }
From source file:com.redhat.rhn.domain.kickstart.RepoInfo.java
/** * Returns all the 4 standard repos available to rhel 5 * cluster, clusterstorage, workstation and VT * @param tree the kickstartable tree/*from ww w .ja v a2 s . co m*/ * @return the standard repos.. */ public static List<RepoInfo> getStandardRepos(KickstartableTree tree) { ArrayList<RepoInfo> repoList = new ArrayList<RepoInfo>(); String[] repos = { "Cluster", "ClusterStorage", "HighAvailability", "LoadBalancer", "ResilientStorage", "VT", "Workstation", "ScalableFileSystem" }; for (String repo : repos) { File file = new File(StringUtil.addPath(tree.getAbsolutePath(), repo)); if (file.exists()) { File repodata = new File( file.getPath() + File.separator + "repodata" + File.separator + "repomd.xml"); repoList.add(create(repo, repo, repodata.exists())); } } return repoList; }
From source file:Main.java
public static File getOutputMediaFile(Context mContext) { File mediaStorageDir = mContext.getExternalFilesDir(cacheCampareImage); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; }/*from ww w . j a va2s .co m*/ } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return mediaFile; }