本文整理了Java中org.openide.filesystems.FileUtil.normalizeFile()
方法的一些代码示例,展示了FileUtil.normalizeFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.normalizeFile()
方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:normalizeFile
[英]Normalize a file path to a clean form. This method may for example make sure that the returned file uses the natural case on Windows; that old Windows 8.3 filenames are changed to the long form; that relative paths are changed to be absolute; that .
and ..
sequences are removed; etc. Unlike File#getCanonicalFile this method will not traverse symbolic links on Unix.
This method involves some overhead and should not be called frivolously. Generally it should be called on incoming pathnames that are gotten from user input (including filechoosers), configuration files, Ant properties, etc. Internal calculations should not need to renormalize paths since File#listFiles, File#getParentFile, etc. will not produce abnormal variants.
[中]将文件路径规范化为干净的表单。例如,此方法可以确保返回的文件在Windows上使用自然大小写;旧的Windows 8.3文件名改为长格式;将相对路径更改为绝对路径;删除.
和..
序列;与File#getCanonicalFile不同,此方法不会在Unix上遍历符号链接。
此方法涉及一些开销,不应随意调用。通常,应该对从用户输入(包括文件选择器)、配置文件、Ant属性等获取的传入路径名调用它。内部计算不需要重新规范化路径,因为文件#listFiles、文件#getParentFile等不会产生异常变体。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
void locateCurrent() {
FileObject oldCurrent = current;
currentF = FileUtil.normalizeFile(path);
while (true) {
current = FileUtil.toFileObject(currentF);
if (current != null) {
isOnTarget = path.equals(currentF);
break;
}
currentF = currentF.getParentFile();
if (currentF == null) {
// #47320: can happen on Windows in case the drive does not exist.
// (Inside constructor for Holder.) In that case skip it.
return;
}
}
assert current != null;
if (current != oldCurrent) {
if (oldCurrent != null) {
oldCurrent.removeFileChangeListener(this);
}
current.addFileChangeListener(this);
current.getChildren(); //to get events about children
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private void setJarFile(final File aRoot, boolean refreshRoot, boolean openJar)
throws IOException, PropertyVetoException {
if (!aRoot.equals(FileUtil.normalizeFile(aRoot))) {
throw new IllegalArgumentException(
"Parameter aRoot was not " + // NOI18N
"normalized. Was " + aRoot + " instead of " + FileUtil.normalizeFile(aRoot)
setJar(tempJar);
openRequestTime = System.currentTimeMillis();
root = new File(s);
foRoot = FileUtil.toFileObject(root);
代码示例来源:origin: org.codehaus.mevenide/nb-project
public static File convertStringToFile(String str) {
if (str != null) {
File fil = new File(str);
return FileUtil.normalizeFile(fil);
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial
/**
* Returns the administrative hg folder for the given repository and normalizes the file
* @param repositoryRoot root of the repository
* @return administrative hg folder
*/
public static File getHgFolderForRoot (File repositoryRoot) {
return FileUtil.normalizeFile(new File(repositoryRoot, HG_FOLDER_NAME));
}
代码示例来源:origin: org.codehaus.mevenide/nb-project
public static FileObject convertStringToFileObject(String str) {
if (str != null) {
File fil = new File(str);
fil = FileUtil.normalizeFile(fil);
return FileUtil.toFileObject(fil);
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial
public LocalFileDiffStreamSource (File file, boolean isRight) {
this.file = FileUtil.normalizeFile(file);
this.fileObject = FileUtil.toFileObject(this.file);
this.isRight = isRight;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-clientproject
private File getNormalizedFile(String path) {
if (path == null) {
return null;
}
return FileUtil.normalizeFile(new File(path));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javacard-spi
@Override
public Collection<FileObject> getInstallFolders() {
String prop = System.getProperty("java.home"); //NOI18N
File f = FileUtil.normalizeFile (new File (prop));
return Collections.<FileObject>singleton(FileUtil.toFileObject(f));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial
/**
* Sets the file for which the annotations are displayed. This file can differ from the displayed one when showing annotations
* for a file in the past.
* @param file
*/
void setReferencedFile(File file) {
this.referencedFile = FileUtil.normalizeFile(file);
this.referencedFileObject = FileUtil.toFileObject(file);
}
}
代码示例来源:origin: org.codehaus.mevenide/nb-project
public static URI convertStringToUri(String str) {
if (str != null) {
File fil = new File(str);
fil = FileUtil.normalizeFile(fil);
return fil.toURI();
}
return null;
}
代码示例来源:origin: org.codehaus.mevenide/nb-project
public static FileObject[] convertStringsToFileObjects(List<String> strings) {
FileObject[] fos = new FileObject[strings.size()];
int index = 0;
Iterator<String> it = strings.iterator();
while (it.hasNext()) {
String str = it.next();
File fil = new File(str);
fil = FileUtil.normalizeFile(fil);
fos[index] = FileUtil.toFileObject(fil);
index++;
}
return fos;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-localhistory
/**
* Normalizes the given file and return a FileObject
* @param file
* @return
*/
public static FileObject toFileObject(File file) {
File nfile = FileUtil.normalizeFile(file);
if(nfile != null) {
return FileUtil.toFileObject(nfile);
} else {
return FileUtil.toFileObject(file);
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-maven-embedder
/**
* the location of ${user.home}/.m2
*/
public File getM2UserDir() {
return FileUtil.normalizeFile(new File(System.getProperty("user.home"), ".m2"));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-clientproject
private FileObject createLibrariesFolder() {
int i = 0;
for (;;) {
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "netbeans-jslibs-" + i++); // NOI18N
if (!tmpDir.isDirectory() && tmpDir.mkdirs()) {
FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(tmpDir));
if (fo != null && fo.isValid()) {
return fo;
}
}
}
}
代码示例来源:origin: org.codehaus.mevenide/nb-project
public FileObject getRootFolder() {
FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(art.getFile()));
if (fo != null) {
return FileUtil.getArchiveRoot(fo);
}
return null;
}
代码示例来源:origin: org.codehaus.mevenide/nb-mvn-embedder
/**
* the location of ${user.home}/.m2
*/
public File getM2UserDir() {
return FileUtil.normalizeFile(new File(System.getProperty("user.home"), ".m2"));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui
private void selectAbsoluteResource(Matcher m) {
String resource = "/" + m.group(1) + m.group(4); //NOI18N
int lineNumber = Integer.parseInt(m.group(5));
File file = new File(resource);
if (file.exists()) {
FileObject source = FileUtil.toFileObject(FileUtil.normalizeFile(file));
doOpen(source, lineNumber);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
private void addFiles(List<File> files) throws IOException {
for( File file : files ) {
final FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file.getAbsoluteFile()));
if (fo == null) {
throw new IOException("no file object for " + file); // NOI18N
} else {
addFile(fo);
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-rakeproject
/**
* Location in user directory of per-user global properties.
* May be null if <code>netbeans.user</code> is not set.
*/
static File userBuildProperties() {
String nbuser = System.getProperty("netbeans.user"); // NOI18N
if (nbuser != null) {
return FileUtil.normalizeFile(new File(nbuser, "build.properties")); // NOI18N
} else {
return null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject
@Override
protected FileObject getTargetFO(String fileName, FileObject sourceFO) {
File targetFile = new File(getTargetFilePath(fileName, sourceFO));
FileObject targetFO = FileUtil.toFileObject(FileUtil.normalizeFile(targetFile));
// do not navigate to itself
if (sourceFO.equals(targetFO)) {
return null;
}
return targetFO;
}
内容来源于网络,如有侵权,请联系作者删除!