本文整理汇总了Java中org.openide.filesystems.FileUtil.toFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.toFile方法的具体用法?Java FileUtil.toFile怎么用?Java FileUtil.toFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileUtil
的用法示例。
在下文中一共展示了FileUtil.toFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
File f = FileUtil.toFile(
matchingObject.getFileObject());
if (f != null) {
String path = f.getPath();
Clipboard clipboard = Lookup.getDefault().lookup(
ExClipboard.class);
if (clipboard == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit != null) {
clipboard = toolkit.getSystemClipboard();
}
}
if (clipboard != null) {
StringSelection strSel = new StringSelection(path);
clipboard.setContents(strSel, null);
}
}
}
示例2: findPlatformSources
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
*/
private ClassPath findPlatformSources(final String javaExecutable) {
/* Copied from JavaAntLogger */
final JavaPlatform[] platforms = JavaPlatformManager.getDefault()
.getInstalledPlatforms();
for (int i = 0; i < platforms.length; i++) {
FileObject fo = platforms[i].findTool("java"); //NOI18N
if (fo != null) {
File f = FileUtil.toFile(fo);
if (f.getAbsolutePath().startsWith(javaExecutable)) {
return platforms[i].getSourceFolders();
}
}
}
return null;
}
示例3: testCopyWithInnerProjectSimple
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testCopyWithInnerProjectSimple() throws Exception {
TestUtil.createFileFromContent(DefaultProjectOperationsImplementationTest.class.getResource("data/test.txt"), projdir, "lib/test.txt");
FileObject projdir2 = projdir.createFolder("proj2");
createProject(projdir2);
ProgressHandle handle = ProgressHandleFactory.createHandle("test-handle");
handle.start(DefaultProjectOperationsImplementation.MAX_WORK);
FileObject newTarget = prj.getProjectDirectory().getParent();
DefaultProjectOperationsImplementation.doCopyProject(handle, prj, "projCopy", newTarget);
File newProject = new File(FileUtil.toFile(newTarget), "projCopy");
assertTrue(newProject.isDirectory());
assertTrue(new File(newProject, "nbproject").isDirectory());
assertTrue(new File(newProject, "src").isDirectory());
assertTrue(new File(newProject, "lib").isDirectory());
assertFalse(new File(newProject, "proj2").exists());
}
示例4: getOpenFiles
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Returns files from all opened top components
* @return set of opened files
*/
public static Set<File> getOpenFiles() {
TopComponent[] comps = TopComponent.getRegistry().getOpened().toArray(new TopComponent[0]);
Set<File> openFiles = new HashSet<File>(comps.length);
for (TopComponent tc : comps) {
Node[] nodes = tc.getActivatedNodes();
if (nodes == null) {
continue;
}
for (Node node : nodes) {
File file = node.getLookup().lookup(File.class);
if (file == null) {
FileObject fo = node.getLookup().lookup(FileObject.class);
if (fo != null && fo.isData()) {
file = FileUtil.toFile(fo);
}
}
if (file != null) {
openFiles.add(file);
}
}
}
return openFiles;
}
示例5: setUp
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
protected @Override void setUp() throws Exception {
clearWorkDir();
File u = new File(getWorkDir(), "userdir");
File uc = new File(u, "config");
uc.mkdirs();
System.setProperty("netbeans.user", u.toString());
File h = new File(getWorkDir(), "nb/installdir");
new File(h, "config").mkdirs();
System.setProperty("netbeans.home", h.toString());
File moduleJar = createModuleJar( manifest );
mgr = Main.getModuleSystem().getManager();
System.setProperty("installer.done", "false");
FileObject[] arr = FileUtil.getConfigRoot().getChildren();
FileUtil.getConfigRoot().addFileChangeListener(this);
try {
mgr.mutexPrivileged().enterWriteAccess();
myModule = mgr.create( moduleJar, null, true, false, false );
mgr.enable( myModule );
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
assertNotNull("Module layer is installed", FileUtil.getConfigFile( "foo" ) );
configDir = FileUtil.toFile( FileUtil.getConfigRoot() );//new File( getWorkDir(), "userdir/config" );
}
示例6: projectToOutputDir
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private String projectToOutputDir(Project p, File basedir) {
//attempt to resolve a relative path to save space on the cmd line..
File f = new File(new File(FileUtil.toFile(p.getProjectDirectory()), "target"), "classes");
String toRet = basedir != null ? FileUtilities.relativizeFile(basedir, f) : null;
if (toRet == null) {
toRet = f.getAbsolutePath();
}
return toRet;
}
示例7: getProjectRootFiles
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Returns all root files for the given {@link Project}
*
* @param project
* @return
*/
public static File[] getProjectRootFiles(Project project){
if (project == null) return null;
Set<File> set = new HashSet<File>();
Sources sources = ProjectUtils.getSources(project);
SourceGroup [] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
for (int j = 0; j < sourceGroups.length; j++) {
SourceGroup sourceGroup = sourceGroups[j];
FileObject srcRootFo = sourceGroup.getRootFolder();
File rootFile = FileUtil.toFile(srcRootFo);
set.add(rootFile);
}
return set.toArray(new File[set.size()]);
}
示例8: toPath
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static String toPath (FileObject[] cpRoots) {
StringBuffer result = new StringBuffer ();
for (int i=0; i<cpRoots.length; i++) {
if (i>0) {
result.append(':'); //NOI18N
}
File f = FileUtil.toFile (cpRoots[i]);
result.append (f.getAbsolutePath());
}
return result.toString();
}
示例9: getProjectBaseDir
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private File getProjectBaseDir() {
try {
return FileUtil.toFile(Utilities.actionsGlobalContext().lookup(Project.class).getProjectDirectory());
} catch (Exception e) {
return new File("");
}
}
示例10: btnJavadocActionPerformed
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@Messages("LBL_Edit_Jar_Panel_browse=Select JAR/folder")
private void btnJavadocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJavadocActionPerformed
// Let user search for the Jar file
FileChooser chooser;
if (helper.isSharableProject()) {
chooser = new FileChooser(helper, true);
} else {
chooser = new FileChooser(FileUtil.toFile(helper.getProjectDirectory()), null);
}
chooser.enableVariableBasedSelection(true);
chooser.setFileHidingEnabled(false);
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(false);
chooser.setDialogTitle(LBL_Edit_Jar_Panel_browse());
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(new SimpleFileFilter(
"Javadoc Entry (folder, ZIP or JAR file)",
new String[]{"ZIP", "JAR"})); // NOI18N
File curDir = helper.resolveFile(helper.getStandardPropertyEvaluator().evaluate(item.getJarFile()));
chooser.setCurrentDirectory(curDir);
int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
if (option == JFileChooser.APPROVE_OPTION) {
String files[];
try {
files = chooser.getSelectedPaths();
} catch (IOException ex) {
// TODO: add localized message
Exceptions.printStackTrace(ex);
return;
}
txtJavadoc.setText(chooser.getSelectedPathVariables() != null ? stripOffVariableMarkup(chooser.getSelectedPathVariables()[0]) : files[0]);
}
}
示例11: btnSourceActionPerformed
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void btnSourceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSourceActionPerformed
FileChooser chooser;
if (helper.isSharableProject()) {
chooser = new FileChooser(helper, true);
} else {
chooser = new FileChooser(FileUtil.toFile(helper.getProjectDirectory()), null);
}
chooser.enableVariableBasedSelection(true);
chooser.setFileHidingEnabled(false);
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(false);
chooser.setDialogTitle(LBL_Edit_Jar_Panel_browse());
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(new SimpleFileFilter(
"Source Entry (folder, ZIP or JAR file)",
new String[]{"ZIP", "JAR"})); // NOI18N
File curDir = helper.resolveFile(helper.getStandardPropertyEvaluator().evaluate(item.getJarFile()));
chooser.setCurrentDirectory(curDir);
int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
if (option == JFileChooser.APPROVE_OPTION) {
String files[];
try {
files = chooser.getSelectedPaths();
} catch (IOException ex) {
// TODO: add localized message
Exceptions.printStackTrace(ex);
return;
}
txtSource.setText(chooser.getSelectedPathVariables() != null ? stripOffVariableMarkup(chooser.getSelectedPathVariables()[0]) : files[0]);
}
}
示例12: getIndex
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public static File getIndex(URL url) throws IOException {
url = CachingArchiveProvider.getDefault().mapCtSymToJar(url);
FileObject indexBaseFolder = CacheFolder.getDataFolder(url);
String path = SPIAccessor.getInstance().getIndexerPath(NAME, VERSION);
FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path);
return FileUtil.toFile(indexFolder);
}
示例13: run
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void run() {
final Set<File> result = new HashSet<File>();
// Search in the source groups of the projects.
for (SourceGroup group : ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
for (FileObject fo : NbCollections.iterable(group.getRootFolder().getChildren(true))) {
if (Thread.currentThread().isInterrupted()) {
return;
}
if (!SpringConstants.CONFIG_MIME_TYPE.equals(fo.getMIMEType())) {
continue;
}
File file = FileUtil.toFile(fo);
if (file == null) {
continue;
}
result.add(file);
}
}
// Search any providers of Spring config files registered in the project lookup.
for (SpringConfigFileProvider provider : project.getLookup().lookupAll(SpringConfigFileProvider.class)) {
if (Thread.currentThread().isInterrupted()) {
return;
}
result.addAll(provider.getConfigFiles());
}
final List<File> sorted = new ArrayList<File>(result.size());
sorted.addAll(result);
Collections.sort(sorted);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateAvailableFiles(sorted);
}
});
}
示例14: execute
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void execute(Action action, TestConfig config) throws IOException {
RunConfig rc;
if (Action.DEBUG_TESTSUITE.equals(action)
|| Action.DEBUG_TEST.equals(action)
|| Action.DEBUG_TESTMETHOD.equals(action)) {
rc = new TestNGActionsProvider().createConfigForDefaultAction("testng.debug", p, Lookups.singleton(config.getTest()));
} else {
rc = new TestNGActionsProvider().createConfigForDefaultAction("testng.test", p, Lookups.singleton(config.getTest()));
}
// MavenProject mp = rc.getMavenProject();
rc.setProperty("netbeans.testng.action", "true"); //NOI18N
if (config.doRerun()) {
copy(getFailedConfig());
// mp.addPlugin(createPluginDef(failedConfPath));
} else {
File f = null;
if (Action.RUN_TESTSUITE.equals(action) || Action.DEBUG_TESTSUITE.equals(action)) {
f = FileUtil.toFile(config.getTest());
} else {
f = XMLSuiteSupport.createSuiteforMethod(
new File(System.getProperty("java.io.tmpdir")), //NOI18N
ProjectUtils.getInformation(p).getDisplayName(),
config.getPackageName(),
config.getClassName(),
config.getMethodName());
}
f = FileUtil.normalizeFile(f);
copy(FileUtil.toFileObject(f));
// mp.addPlugin(createPluginDef(FileUtil.getRelativePath(p.getProjectDirectory(), FileUtil.toFileObject(f))));
}
ExecutorTask task = RunUtils.executeMaven(rc);
}
示例15: computeDiff
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Create the differences of the content of two FileObjects.
* @param fo1 the first FileObject
* @param fo2 the second FileObject to be compared with the first one.
* @return the list of differences found, instances of {@link Difference};
* or <code>null</code> when some error occured.
*/
public Difference[] computeDiff(FileObject fo1, FileObject fo2) throws IOException {
File f1 = FileUtil.toFile(fo1);
File f2 = FileUtil.toFile(fo2);
if (f1 != null && f2 != null) {
return createDiff(f1, f2);
} else {
return null;
}
}