List of usage examples for java.io File getName
public String getName()
From source file:com.siva.filewritterprogram.Mp3FileWritterTool.java
public static void main(String[] args) { File directory = new File("D:\\Siva\\Entertainment\\EvergreenHits"); FileFilter filter = new FileFilter() { @Override//from ww w. ja v a2s.c o m public boolean accept(File file) { if (file.getName().endsWith(".mp3")) { return true; } else { return false; } } }; File[] subdirs = directory.listFiles(); for (File subDir : subdirs) { try { System.out.println("Going to read files under : " + subDir); if (subDir.isDirectory()) { File[] files = subDir.listFiles(filter); if (files != null) { for (File file : files) { FileUtils.copyFileToDirectory(file, new File(directory.getPath() + "\\toTransfer")); } } else { System.out.println("There are no songs inside. [" + subDir.getName() + "]"); } } else { System.out.println("Not a directory. [" + subDir.getName() + "]"); } } catch (IOException ex) { Logger.getLogger(Mp3FileWritterTool.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:Main.java
public static void main(String[] args) { File dir = new File("c:\\"); File[] files = dir.listFiles(); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; System.out.printf("File %s - %2$tm %2$te,%2$tY%n= ", file.getName(), file.lastModified()); }//from www. j a v a 2 s . c o m Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); for (int i = 0; i < files.length; i++) { File file = files[i]; System.out.printf("File %s - %2$tm %2$te,%2$tY%n= ", file.getName(), file.lastModified()); } }
From source file:MainClass.java
public static void main(String[] a) { File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); System.out.println(myFile.getName()); System.out.println(myFile.getPath()); }
From source file:MainClass.java
public static void main(String args[]) { File f1 = new File("MainClass.java"); System.out.println("File Name:" + f1.getName()); System.out.println("Path:" + f1.getPath()); System.out.println("Abs Path:" + f1.getAbsolutePath()); System.out.println("Parent:" + f1.getParent()); System.out.println(f1.exists() ? "exists" : "does not exist"); System.out.println(f1.canWrite() ? "is writeable" : "is not writeable"); System.out.println(f1.canRead() ? "is readable" : "is not readable"); System.out.println("is a directory" + f1.isDirectory()); System.out.println(f1.isFile() ? "is normal file" : "might be a named pipe"); System.out.println(f1.isAbsolute() ? "is absolute" : "is not absolute"); System.out.println("File last modified:" + f1.lastModified()); System.out.println("File size:" + f1.length() + " Bytes"); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] properties = { "os.name", "java.version", "java.vm.version", "java.vendor" }; for (String property : properties) { System.out.println(property + ": " + System.getProperty(property)); }// ww w .j a va 2 s .c om JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(null); jfc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj"); } @Override public String getDescription() { return "Wavefront OBJ (*.obj)"; } @Override public String toString() { return getDescription(); } }); int result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(jfc); jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(jfc); break; } } jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); }
From source file:Main.java
public static void main(String[] args) { File aFile; try {/*w ww . ja va2 s .c o m*/ aFile = new File(new URI("file:///c:/a.bat")); System.out.println(aFile.getName());//false } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:JFileChooserTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JComboBox Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select File"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println(selectedFile.getName()); }//from ww w. ja v a 2s . com } }); frame.add(button); frame.pack(); frame.setVisible(true); }
From source file:com.carteblanche.kwd.driver.KeywordDrivenDriver.java
public static void main(String[] args) { File[] listOfFiles;// w w w . j a va 2 s . com File folder = new File(testDirectory + testSuiteName + "/"); String testSuiteName = folder.getName(); testSuiteName = StringUtils .capitalize(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(testSuiteName), ' ')); listOfFiles = folder.listFiles(); TestNGDriver testNGDriver = new TestNGDriver(); int i = 0; for (File csv : listOfFiles) { KWDTestCase testCase = TestCaseParser.parse(csv, cvsSplitBy); testNGDriver.runTests(testCase, testSuiteName + i, folder.getName()); i++; } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("filename"); File dir = new File("directoryname"); boolean success = file.renameTo(new File(dir, file.getName())); if (!success) { System.out.println("File was not successfully moved"); }//from w w w . j a v a2 s. c om }
From source file:com.apipulse.bastion.Main.java
public static void main(String[] args) throws IOException, ClassNotFoundException { log.info("Bastion starting. Loading chains"); final File dir = new File("etc/chains"); final LinkedList<ActorRef> chains = new LinkedList<ActorRef>(); for (File file : dir.listFiles()) { if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) { log.info("Loading chain: " + file.getName()); ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file))); ActorRef ref = BastionActors.getInstance().initChain(config.getName(), Class.forName(config.getQualifiedClass())); Iterator<StageConfig> iterator = config.getStages().iterator(); while (iterator.hasNext()) ref.tell(iterator.next(), null); chains.add(ref);/*from www .ja v a 2 s . c o m*/ } } SpringApplication app = new SpringApplication(); HashSet<Object> objects = new HashSet<Object>(); objects.add(ApiController.class); final ConfigurableApplicationContext context = app.run(ApiController.class, args); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { log.info("Bastion shutting down"); Iterator<ActorRef> iterator = chains.iterator(); while (iterator.hasNext()) iterator.next().tell(new StopMessage(), null); Thread.sleep(2000); context.stop(); log.info("Bastion shutdown complete"); } catch (Exception e) { } } }); }