@Override public void compile() { File file = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath() + "/ezTex"); File[] files = file.listFiles(); System.out.println("Wähle eine Datei aus:"); for (int i = 0; i < files.length; i++) System.out.println("\t" + i + ": " + files[i].getName()); int chosen = sc.nextInt(); if (chosen > files.length) return; File chosenFile = new File(files[chosen].getAbsolutePath() + "/" + files[chosen].getName() + ".eztex"); System.out.println(chosenFile.getAbsolutePath()); startCompiler(readFile(chosenFile), chosenFile); }
/** ������ݷ�ʽ */ private void createShortcut() { // ��ȡϵͳ����·�� String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath(); // ����ִ���ļ�·�� String appPath = System.getProperty("user.dir"); File exePath = new File(appPath).getParentFile(); JShellLink link = new JShellLink(); link.setFolder(desktop); link.setName("Notebook.exe"); link.setPath(exePath.getAbsolutePath() + File.separator + "Notebook.exe"); // link.setArguments("form"); link.save(); System.out.println("======== create success ========"); }
public void testValidRoots () throws Exception { assertNotNull(testedFS.getRoot()); assertTrue(testedFS.getRoot().isValid()); FileSystemView fsv = FileSystemView.getFileSystemView(); File[] roots = File.listRoots(); boolean validRoot = false; for (int i = 0; i < roots.length; i++) { FileObject root1 = FileUtil.toFileObject(roots[i]); if (!roots[i].exists()) { assertNull(root1); continue; } assertNotNull(roots[i].getAbsolutePath (),root1); assertTrue(root1.isValid()); if (testedFS == root1.getFileSystem()) { validRoot = true; } } assertTrue(validRoot); }
public void testNormalizeDrivesOnWindows48681 () { if ((Utilities.isWindows () || (Utilities.getOperatingSystem () == Utilities.OS_OS2))) { File[] roots = File.listRoots(); for (int i = 0; i < roots.length; i++) { File file = roots[i]; if (FileSystemView.getFileSystemView().isFloppyDrive(file) || !file.exists()) { continue; } File normalizedFile = FileUtil.normalizeFile(file); File normalizedFile2 = FileUtil.normalizeFile(new File (file, ".")); assertEquals (normalizedFile.getPath(), normalizedFile2.getPath()); } } }
private static File getCurrentDirectory() { if (Boolean.getBoolean("netbeans.openfile.197063")) { // Prefer to open from parent of active editor, if any. TopComponent activated = TopComponent.getRegistry().getActivated(); if (activated != null && WindowManager.getDefault().isOpenedEditorTopComponent(activated)) { DataObject d = activated.getLookup().lookup(DataObject.class); if (d != null) { File f = FileUtil.toFile(d.getPrimaryFile()); if (f != null) { return f.getParentFile(); } } } } // Otherwise, use last-selected directory, if any. if(currentDirectory != null && currentDirectory.exists()) { return currentDirectory; } // Fall back to default location ($HOME or similar). currentDirectory = FileSystemView.getFileSystemView().getDefaultDirectory(); return currentDirectory; }
private void doDirectoryChanged(PropertyChangeEvent e) { JFileChooser fc = getFileChooser(); FileSystemView fsv = fc.getFileSystemView(); clearIconCache(); File currentDirectory = fc.getCurrentDirectory(); this.fileList.updatePath(currentDirectory); if (currentDirectory != null) { this.directoryComboBoxModel.addItem(currentDirectory); getNewFolderAction().setEnabled(currentDirectory.canWrite()); getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory)); getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory)); getGoHomeAction().setEnabled(!userHomeDirectory.equals(currentDirectory)); if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) { if (fsv.isFileSystem(currentDirectory)) { setFileName(currentDirectory.getPath()); } else { setFileName(null); } setFileSelected(); } } }
public static Optional<String> checkForUpdate() throws IOException { File oldJar = new File(new File(FileSystemView.getFileSystemView().getDefaultDirectory(), "OneClient"), "temp_update.jar"); if (oldJar.exists()) { oldJar.delete(); } String json = ""; try { json = IOUtils.toString(new URL(updateURL), StandardCharsets.UTF_8); } catch (UnknownHostException e) { OneClientLogging.error(e); return Optional.empty(); } LauncherUpdate launcherUpdate = JsonUtil.GSON.fromJson(json, LauncherUpdate.class); if (Constants.getVersion() == null) { return Optional.empty(); } if (launcherUpdate.compareTo(new LauncherUpdate(Constants.getVersion())) > 0) { return Optional.of(launcherUpdate.latestVersion); } return Optional.empty(); }
public static void main(String[] args) { File dir = FileSystemView.getFileSystemView().getDefaultDirectory(); printDirContent(dir); System.setSecurityManager(new SecurityManager()); // The next test cases use 'dir' obtained without SecurityManager try { printDirContent(dir); throw new RuntimeException("Dir content was derived bypass SecurityManager"); } catch (AccessControlException e) { // It's a successful situation } }
@Override public void loadWorld() { FileSystemView vueSysteme = FileSystemView.getFileSystemView(); File defaut = vueSysteme.getDefaultDirectory(); JFileChooser fileChooser = new JFileChooser(defaut); fileChooser.showDialog(this, "Load"); if(fileChooser.getSelectedFile() != null){ File file = new File(fileChooser.getSelectedFile().getAbsolutePath()); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "Map Loader"); fileChooser.setFileFilter(filter); try { this.mapDao.addMap(WorldLoader.genRawMapFILE(file)); } catch (Exception e) { e.printStackTrace(); } } }
public static void main(String[] args) throws Exception { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) > 0 ) { FileSystemView fsv = FileSystemView.getFileSystemView(); for (File file : fsv.getFiles(fsv.getHomeDirectory(), false)) { if(file.isDirectory()) { for (File file1 : fsv.getFiles(file, false)) { if(file1.isDirectory()) { String path = file1.getPath(); if(path.startsWith("::{") && path.toLowerCase().endsWith(".library-ms")) { throw new RuntimeException("Unconverted library link found"); } } } } } } System.out.println("ok"); }
public static boolean checkBrowser() { AppList appList = MimeTypesList.getAppList(); String bpath = appList.getBrowserExec(); if (bpath != null) if (new File(bpath).isFile()) return true; File root = new File(System.getProperty("user.home")); FileSystemView fsv = new SingleRootFileSystemView(root); JFileChooser chooser = new JFileChooser(fsv); chooser.setFileHidingEnabled(true); chooser.setDialogTitle(Local.getString("Select the web-browser executable")); chooser.setAcceptAllFileFilterUsed(true); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); /*java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_RESOURCE_FILE"); if (lastSel != null) chooser.setCurrentDirectory(lastSel);*/ if (chooser.showOpenDialog(App.getFrame()) != JFileChooser.APPROVE_OPTION) return false; appList.setBrowserExec(chooser.getSelectedFile().getPath()); CurrentStorage.get().storeMimeTypesList(); return true; }
/*** * Get Disk information. */ private static void getDiskInfo(){ File[] drives = File.listRoots(); systemDiskUsage.clear(); systemInfo.clear(); if(drives != null && drives.length > 0){ for(File disk : drives){ long totalSpace = disk.getTotalSpace(); long usedSpace = totalSpace - disk.getFreeSpace(); double usage = (double)usedSpace * 100 / (double)totalSpace; systemDiskUsage.put(disk.toString(), usage); FileSystemView fsv = FileSystemView.getFileSystemView(); systemInfo.put(disk.toString(), fsv.getSystemTypeDescription(disk)); } } }
/** * 파일로부터 이미지를 그리기 위한 뷰를 반환한다. * * @Date 2015. 10. 14. * @param file * @return * @User KYJ */ public static ImageView createImageIconView(File file) { Image fxImage = null; if (file.exists()) { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); Icon icon = fileSystemView.getSystemIcon(file); BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, bufferedImage.getGraphics(), 0, 0); fxImage = SwingFXUtils.toFXImage(bufferedImage, null); } else { return new ImageView(); } return new ImageView(fxImage); }
public static void cleanUp() { //gets rid of scratch files. FileSystemView Directories = FileSystemView.getFileSystemView(); File homedir = Directories.getHomeDirectory(); String homedirpath = homedir.getPath(); String scratchpath = homedirpath + "/.jmol_WPM"; File scratchdir = new File(scratchpath); if (scratchdir.exists()) { File[] dirListing = null; dirListing = scratchdir.listFiles(); for (int i = 0; i < (dirListing.length); i++) { dirListing[i].delete(); } } saveHistory();//force save of history. }
protected void setup(FileSystemView view) { super.setup(view); removeChoosableFileFilter(getAcceptAllFileFilter()); xml = new SuffixedFileFilter("xml"); addChoosableFileFilter(xml); msAccess = new SuffixedFileFilter("mdb"); addChoosableFileFilter(msAccess); fileMaker = new SuffixedFileFilter("fmp"); addChoosableFileFilter(fileMaker); odbc = new SuffixedFileFilter("dsn"); addChoosableFileFilter(odbc); addChoosableFileFilter(getAcceptAllFileFilter()); setFileFilter(xml); }
/** * Abre una ventana emergente para escoger la direccion en la cual se quiere * almacenar la hoja de datos de Excel */ public void exportExcelFile() throws FileNotFoundException, IOException { JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getDefaultDirectory()); int returnValue = jfc.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = jfc.getSelectedFile(); String path = selectedFile.getAbsolutePath(); if (!path.endsWith(".xlsx")) { path += ".xlsx"; } FileOutputStream outputStream = new FileOutputStream(path); XSSFWorkbook workbook = buildSpreadsheet(); workbook.write(outputStream); } }
public void openFile() throws IOException { JFileChooser chooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || isHtml(f); } @Override public String getDescription() { return "HTML files"; } }); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); watcher.watch(chosenFile); watchedFilePath = chosenFile.getPath(); } }
public static String getMinecraftFolderLocation() { if (Platform.isWindows()) { String worldFolder = System.getenv("APPDATA"); if (worldFolder.endsWith("Roaming")) { worldFolder = worldFolder.replace("\\AppData\\Roaming", "\\AppData\\Local"); } StringBuilder folder = new StringBuilder(worldFolder); folder.append("\\Packages") //.append(getMinecraftFolderName(folder.toString())) .append("\\Microsoft.MinecraftUWP_") .append(MicrosoftPublisherID) .append("\\LocalState\\games\\com.mojang\\minecraftWorlds"); System.out.println("Minecraft worlds folder: " + folder.toString()); if (new File(folder.toString()).exists()) { return folder.toString(); } } return FileSystemView.getFileSystemView().getDefaultDirectory().getPath(); }
public void createNewFile() { String buildBatContext = "@echo off \nC: \ncd %~dp0 \ncd .. \npdflatex ez.tex \npdflatex ez.tex \nexit"; try { String fileName; System.out.println("Dateiname: ( _ == Default[Datum])"); fileName = sc.next(); if (fileName.equals("_")) { DateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); Date date = new Date(); fileName = "/" + df.format(date); } File file = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath() + "/ezTex/" + fileName); if (!file.exists()) { file.mkdirs(); } File ezTex = new File(file.getAbsolutePath() + "/" + fileName + ".eztex"); ezTex.createNewFile(); File imgFolder = new File(ezTex.getParent() + "/img"); File pdfFolder = new File(ezTex.getParent() + "/pdf"); copyStringToFile(buildBatContext, new File(ezTex.getParent() + "/build/build.bat")); imgFolder.mkdirs(); pdfFolder.mkdirs(); System.out.println("Datei wurde in " + file.getAbsolutePath() + " erstellt."); Desktop.getDesktop().open(file); } catch (IOException e) { e.printStackTrace(); } }
public File getProjectsFolder(boolean create) { String result = getProperty (PROP_PROJECTS_FOLDER); if (result == null || !(new File(result)).exists()) { // property for overriding default projects dir location String userPrjDir = System.getProperty("netbeans.projects.dir"); // NOI18N if (userPrjDir != null) { File f = new File(userPrjDir); if (f.exists() && f.isDirectory()) { return FileUtil.normalizeFile(f); } } if (Boolean.getBoolean("netbeans.full.hack")) { // NOI18N return FileUtil.normalizeFile(new File(System.getProperty("java.io.tmpdir", ""))); // NOI18N } File defaultDir = FileSystemView.getFileSystemView().getDefaultDirectory(); if (defaultDir != null && defaultDir.exists() && defaultDir.isDirectory()) { String nbPrjDirName = NbBundle.getMessage(OpenProjectListSettings.class, "DIR_NetBeansProjects"); File nbPrjDir = new File(defaultDir, nbPrjDirName); if (nbPrjDir.exists() && nbPrjDir.canWrite()) { return nbPrjDir; } else { boolean created = create && nbPrjDir.mkdir(); if (created) { // #75960 - using Preferences to temporarily save created projects folder path, // folder will be deleted after wizard is finished if nothing was created in it getPreferences().put(PROP_CREATED_PROJECTS_FOLDER, nbPrjDir.getAbsolutePath()); return nbPrjDir; } } } result = System.getProperty("user.home"); //NOI18N } return FileUtil.normalizeFile(new File(result)); }
@Override public void actionPerformed(ActionEvent e) { if (UIManager.getBoolean("FileChooser.readOnly")) { return; } JFileChooser fc = getFileChooser(); File currentDirectory = fc.getCurrentDirectory(); FileSystemView fsv = fc.getFileSystemView(); File newFolder = null; String name = SwingTools.showInputDialog("file_chooser.new_folder", ""); try { if (name != null && !"".equals(name)) { newFolder = fsv.createNewFolder(currentDirectory); if (newFolder.renameTo(fsv.createFileObject(fsv.getParentDirectory(newFolder), name))) { newFolder = fsv.createFileObject(fsv.getParentDirectory(newFolder), name); } else { SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.rename", name); } } } catch (IOException exc) { SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.create", name); return; } catch (Exception exp) { // do nothing } if (fc.isMultiSelectionEnabled()) { fc.setSelectedFiles(new File[] { newFolder }); } else { fc.setSelectedFile(newFolder); } fc.rescanCurrentDirectory(); }
/** * Creates file chooser with a reasonable start directory. You may use the following code * snippet in order to retrieve the file: * * <pre> * if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) * File selectedFile = fileChooser.getSelectedFile(); * </pre> * * Usually, the method {@link #chooseFile(Component, File, boolean, boolean, FileFilter[])} or * one of the convenience wrapper methods can be used to do this. This method is only useful if * one is interested, e.g., in the selected file filter. * * @param file * The initially selected value of the file chooser dialog * @param onlyDirs * Only allow directories to be selected * @param fileFilters * List of FileFilters to use */ public static JFileChooser createFileChooser(final String i18nKey, final File file, final boolean onlyDirs, final FileFilter[] fileFilters) { File directory = null; if (file != null) { if (file.isDirectory()) { directory = file; } else { directory = file.getAbsoluteFile().getParentFile(); } } else { directory = FileSystemView.getFileSystemView().getDefaultDirectory(); } JFileChooser fileChooser = new ExtendedJFileChooser(i18nKey, directory); if (onlyDirs) { fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } if (fileFilters != null) { fileChooser.setAcceptAllFileFilterUsed(true); for (FileFilter fileFilter : fileFilters) { fileChooser.addChoosableFileFilter(fileFilter); } if (fileFilters.length > 0) { fileChooser.setFileFilter(fileFilters[0]); } } if (file != null) { fileChooser.setSelectedFile(file); } return fileChooser; }
private void DragFileHandle(final JPanel myPanel) { new FileDrop(myPanel, new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { for (int i = 0; i < files.length; i++) { Icon ico = FileSystemView.getFileSystemView().getSystemIcon(files[i]); FindFiles(myPanel.getName(), files[i]); Image image = ((ImageIcon) ico).getImage(); ImageIcon icon = new ImageIcon(getScaledImage(image, 45, 45)); myPanel.removeAll(); myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS)); JLabel label = new JLabel(); label.setIcon(icon); label.setAlignmentX(CENTER_ALIGNMENT); myPanel.add(Box.createRigidArea(new Dimension(0, 60))); myPanel.add(label, BorderLayout.CENTER); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); JLabel labe2 = new JLabel(files[i].getName(), SwingConstants.CENTER); labe2.setBackground(new Color(240, 240, 240)); labe2.setForeground(new Color(0, 0, 0)); labe2.setFont(new Font("Segoe UI Light", Font.PLAIN, 14)); labe2.setAlignmentX(CENTER_ALIGNMENT); myPanel.add(labe2, BorderLayout.LINE_START); } } }); }
public Image getIconImageFX(File f){ ImageIcon icon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon(f); java.awt.Image img = icon.getImage(); BufferedImage bimg = (BufferedImage) img; Image imgfx = toFXImage(bimg,null); return imgfx; }
public static Object getProperty(String key, Object defaultVal) { Object retval = getUnexpandedProperty(key, defaultVal); try { if (retval instanceof String) { String stringVal = (String) retval; if (stringVal.indexOf("\\$ARCMOVER\\.USERDIR") >= 0) { stringVal = stringVal.replaceAll("\\$ARCMOVER\\.USERDIR", System.getProperty("user.dir")); } if (stringVal.indexOf("\\$ARCMOVER\\.USERHOME") >= 0) { stringVal = stringVal.replaceAll("\\$ARCMOVER\\.USERHOME", System.getProperty("user.home")); } if (stringVal.indexOf("\\$ARCMOVER\\.DEFAULTUSERDIR") >= 0) { stringVal = stringVal.replaceAll("\\$ARCMOVER\\.DEFAULTUSERDIR", FileSystemView .getFileSystemView().getDefaultDirectory().toURI().toString()); } retval = stringVal; } } catch (Exception e) { String msg = "Exception expanding configuration variables for key=" + key + ". Using unexpanded value=" + retval; LOG.log(Level.WARNING, msg, e); } return retval; }
/** {@inheritDoc} */ @Override public Object getValueAt(int rowIndex, int columnIndex) { final File file = files.get(rowIndex); switch (columnIndex) { case 0: return file.getPath(); case 1: return FileSystemView.getFileSystemView().getSystemIcon(file); case 2: return file.isDirectory() ? null : Math.round(file.length() / 1024d); default: return "??"; } }
private static File getDirectory() { if( lastDirectory == null ) { lastDirectory = FileSystemView.getFileSystemView().getDefaultDirectory(); } return lastDirectory; }
public static File getTempFile(boolean startUpdate) { if (startUpdate) { return new File(OperatingSystem.getApplicationDataDirectory(), "temp_update.jar"); } else { //This is to allow updating from versions before the custom dir was added File oldJar = new File(new File(FileSystemView.getFileSystemView().getDefaultDirectory(), "OneClient"), "temp_update.jar"); if (oldJar.exists()) { return oldJar; } return new File(OperatingSystem.getApplicationDataDirectory(), "temp_update.jar"); } }
@Override public Icon getIcon(File f) { if (approve(f)) { return ICON_14; } else { return FileSystemView.getFileSystemView().getSystemIcon(f); } }
private static void checkDefaultDirectory() { if (System.getSecurityManager() == null) { throw new RuntimeException("Security manager is not set!"); } File defaultDirectory = FileSystemView.getFileSystemView(). getDefaultDirectory(); if (defaultDirectory != null) { throw new RuntimeException("File system default directory is null!"); } }
public static void main(String[] args) { System.setSecurityManager(new SecurityManager()); // The next line of code forces FileSystemView to request data from Win32ShellFolder2, // what causes an exception if a security manager installed (see the bug 6570445 description) FileSystemView.getFileSystemView().getRoots(); System.out.println("Passed."); }
private static void test() throws Exception { FileSystemView fsv = FileSystemView.getFileSystemView(); File def = new File(fsv.getDefaultDirectory().getAbsolutePath()); ShellFolderColumnInfo[] defColumns = ShellFolder.getShellFolder(def).getFolderColumns(); File[] files = fsv.getHomeDirectory().listFiles(); for (File file : files) { if( "Libraries".equals(ShellFolder.getShellFolder( file ).getDisplayName())) { File[] libs = file.listFiles(); for (File lib : libs) { ShellFolder libFolder = ShellFolder.getShellFolder(lib); if( "Library".equals(libFolder.getFolderType() ) ) { ShellFolderColumnInfo[] folderColumns = libFolder.getFolderColumns(); for (int i = 0; i < defColumns.length; i++) { if (!defColumns[i].getTitle() .equals(folderColumns[i].getTitle())) throw new RuntimeException("Columnn " + folderColumns[i].getTitle() + " doesn't match " + defColumns[i].getTitle()); } } } } } }
private static void test() { File root = new File("C:\\"); System.out.println("Root Exists: " + root.exists()); System.out.println("Root Absolute Path: " + root.getAbsolutePath()); System.out.println("Root Is Directory?: " + root.isDirectory()); FileSystemView fileSystemView = FileSystemView.getFileSystemView(); NumberFormat nf = NumberFormat.getNumberInstance(); int iMax = 50000; long lastPercentFinished = 0L; for (int i = 0; i < iMax; i++) { long percentFinished = Math.round(((i * 1000d) / (double) iMax)); if (lastPercentFinished != percentFinished) { double pf = ((double) percentFinished) / 10d; String pfMessage = String.valueOf(pf) + " % (" + i + "/" + iMax + ")"; long totalMemory = Runtime.getRuntime().totalMemory() / 1024; long freeMemory = Runtime.getRuntime().freeMemory() / 1024; long maxMemory = Runtime.getRuntime().maxMemory() / 1024; String memMessage = "[Memory Used: " + nf.format(totalMemory) + " kb Free=" + nf.format(freeMemory) + " kb Max: " + nf.format(maxMemory) + " kb]"; System.out.println(pfMessage + " " + memMessage); lastPercentFinished = percentFinished; } boolean floppyDrive = fileSystemView.isFloppyDrive(root); boolean computerNode = fileSystemView.isComputerNode(root); // "isDrive()" seems to be the painful method... boolean drive = fileSystemView.isDrive(root); } }
private static void checkDefaultDirectory() { if (System.getSecurityManager() == null) { throw new RuntimeException("Security manager is not set!"); } File defaultDirectory = FileSystemView.getFileSystemView(). getDefaultDirectory(); if (defaultDirectory != null) { throw new RuntimeException("File system default directory must be null! (FilePermission has not been granted in our policy file)."); } }