本文整理了Java中org.openide.filesystems.FileUtil.copyFile()
方法的一些代码示例,展示了FileUtil.copyFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.copyFile()
方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:copyFile
[英]Copies file to the selected folder. This implementation simply copies the file by stream content. Uses the extension of the source file.
[中]将文件复制到所选文件夹。此实现只需按流内容复制文件。使用源文件的扩展名。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Copies file to the selected folder.
* This implementation simply copies the file by stream content.
* Uses the extension of the source file.
* @param source source file object
* @param destFolder destination folder
* @param newName file name (without extension) of destination file
* @return the created file object in the destination folder
* @exception IOException if <code>destFolder</code> is not a folder or does not exist; the destination file already exists; or
* another critical error occurs during copying
*/
public static FileObject copyFile(FileObject source, FileObject destFolder, String newName)
throws IOException {
return copyFile(source, destFolder, newName, source.getExt());
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Copies content of one folder into another.
* @param source source folder
* @param target target folder
* @exception IOException if it fails
*/
private static void copyContent(FileObject source, FileObject target)
throws IOException {
FileObject[] srcArr = source.getChildren();
copyAttrs(source, target); //added
for (int i = 0; i < srcArr.length; i++) {
FileObject child = srcArr[i];
if (MultiFileSystem.isMaskFile(child)) {
continue;
}
if (target.getFileObject(child.getName(), child.getExt()) == null) {
if (child.isData()) {
FileObject fo = FileUtil.copyFile(child, target, child.getName(), child.getExt());
if (fo != null) {
copyAttrs(child, fo);
}
} else {
FileObject targetChild = target.createFolder(child.getName());
copyContent(child, targetChild);
}
}
}
}
代码示例来源:origin: it.tidalwave.northernwind/it-tidalwave-northernwind-core-filesystem-basic
@Override
public void copyTo (final @Nonnull ResourceFile targetFolder)
throws IOException
{
FileUtil.copyFile(delegate, ((ResourceFileNetBeansPlatform)targetFolder).delegate, delegate.getName());
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Copies file to the selected folder.
* This implementation simply copies the file by stream content.
* Uses the extension of the source file.
* @param source source file object
* @param destFolder destination folder
* @param newName file name (without extension) of destination file
* @return the created file object in the destination folder
* @exception IOException if <code>destFolder</code> is not a folder or does not exist; the destination file already exists; or
* another critical error occurs during copying
*/
public static FileObject copyFile(FileObject source, FileObject destFolder,
String newName) throws IOException {
return copyFile(source, destFolder, newName, source.getExt());
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Copies file to the selected folder.
* This implementation simply copies the file by stream content.
* Uses the extension of the source file.
* @param source source file object
* @param destFolder destination folder
* @param newName file name (without extension) of destination file
* @return the created file object in the destination folder
* @exception IOException if <code>destFolder</code> is not a folder or does not exist; the destination file already exists; or
* another critical error occurs during copying
*/
public static FileObject copyFile(FileObject source, FileObject destFolder,
String newName) throws IOException {
return copyFile(source, destFolder, newName, source.getExt());
}
代码示例来源:origin: nl.cloudfarming.client/sensor-api
/**
* Copy queue to sensor project dir.
*
* @param copyQueue List of files to copy to the archive dir.
* @Param destination FileObject to copy the files to.
* @throws IOException
*/
protected void copy(List<FileObject> copyQueue, FileObject destination) throws IOException {
for (FileObject file : copyQueue) {
try {
FileUtil.copyFile(file, destination, file.getName());
} catch (SyncFailedException ex) {
//Do nothing file already exists
}
}
copyQueue.clear();
}
代码示例来源:origin: nl.cloudfarming.client/isobus-project
/**
* Copy queue to sensor project dir.
*
* @param copyQueue List of files to copy to the archive dir.
* @Param destination FileObject to copy the files to.
* @throws IOException
* @deprecated Move to Util
*/
@Deprecated
public static void copy(List<FileObject> copyQueue, FileObject destination) throws IOException {
for (FileObject file : copyQueue) {
try {
org.openide.filesystems.FileUtil.copyFile(file, destination, file.getName());
} catch (SyncFailedException ex) {
//Do nothing file already exists
}
}
copyQueue.clear();
}
代码示例来源:origin: eu.agrosense.client/util
/**
* Copy queue to specified dir.
*
* @param copyQueue List of files to copy to the specified destination dir.
* @Param destination FileObject to copy the files to.
* @throws IOException
*/
public static void copy(Set<FileObject> copyQueue, FileObject destination) throws IOException {
for (FileObject file : copyQueue) {
try {
org.openide.filesystems.FileUtil.copyFile(file, destination, file.getName());
} catch (SyncFailedException ex) {
//Do nothing file already exists
}
}
copyQueue.clear();
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-profiler
private void exportSnapshot(FileObject selectedSnapshot, FileObject targetFolder, String fileName, String fileExt) {
if (checkFileExists(new SelectedFile(targetFolder, fileName, fileExt))) {
try {
FileUtil.copyFile(selectedSnapshot, targetFolder, fileName, fileExt);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, Bundle.ResultsManager_SnapshotExportFailedMsg(e.getMessage()), e);
}
}
}
代码示例来源:origin: nl.cloudfarming.client/field-project
/**
* Copy sourcefiles to import-folder
* @param dataObject
*/
@Override
public void importSources(DataObject dataObject) {
FileObject importFolder = getImportFolder(true);
Iterator<FileObject> files = dataObject.files().iterator();
while(files.hasNext()){
FileObject current = files.next();
try {
String newFileName = FileUtil.findFreeFileName(importFolder, current.getName(), current.getExt());
FileUtil.copyFile(current, importFolder, newFileName);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
代码示例来源:origin: nl.cloudfarming.client/import
/**
* Copies the specified fileObject to the specified targetFolder. Tries to
* get a free filename for the file object
*
* @param targetFolder the folder the fileObject must be copied to
* @param toCopy the file to be copied
* @return the copied fileObject or null if it could not be copied
*/
private FileObject copy(FileObject targetFolder, FileObject toCopy) {
try {
String newFileName = FileUtil.findFreeFileName(targetFolder, toCopy.getName(), toCopy.getExt());
return FileUtil.copyFile(toCopy, targetFolder, newFileName);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Could not copy file {0} with the exception {1}", new Object[]{toCopy.getName(), ex});
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project
private boolean doCopy(FileObject source, File target) throws IOException {
LOGGER.log(Level.FINE, "Copying file {0} -> {1}", new Object[] {getPath(source), target});
File targetParent = target.getParentFile();
if (source.isData()) {
doDelete(target);
FileObject parent = FileUtil.createFolder(targetParent);
FileUtil.copyFile(source, parent, source.getName(), source.getExt());
LOGGER.log(Level.FINE, "File {0} copied to {1}", new Object[] {getPath(source), target});
} else {
String[] childs = target.list();
if (childs == null || childs.length == 0) {
doDelete(target);
}
FileUtil.createFolder(target);
LOGGER.log(Level.FINE, "Folder {0} created", target);
}
return target.exists();
}
代码示例来源:origin: eu.agrosense.client/import
/**
* Copies the specified FileObject to the specified targetFolder.
*
* <p>
* Tries to get a free filename for the file object</p>
*
* @param targetFolder the folder the fileObject must be copied to
* @param toCopy the file to be copied
* @return the copied fileObject or null if it could not be copied
*/
private FileObject copy(FileObject targetFolder, FileObject toCopy) {
try {
String newFileName = FileUtil.findFreeFileName(targetFolder, toCopy.getName(), toCopy.getExt());
return FileUtil.copyFile(toCopy, targetFolder, newFileName);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Could not copy file {0} with the exception {1}", new Object[]{toCopy.getName(), ex});
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv81
static void copyTemplate(Project proj) throws IOException {
FileObject projDir = proj.getProjectDirectory();
FileObject jnlpBuildFile = projDir.getFileObject("nbproject/extendArchiveGF.xml"); // NOI18N
if (jnlpBuildFile == null) {
FileObject templateFO = FileUtil.getConfigFile("Templates/SunResources/extendArchiveGF.xml"); // NOI18N
if (templateFO != null) {
FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "extendArchiveGF"); // NOI18N
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-testng-maven
private FileObject copy(FileObject source) throws IOException {
FileObject fo = p.getProjectDirectory();
//target/nb-private/tesng-suite.xml
FileObject folder = FileUtil.createFolder(fo, "target/nb-private"); //NOI18N
FileObject cfg = folder.getFileObject("testng-suite", "xml"); //NOI18N
if (cfg != null) {
cfg.delete();
}
return FileUtil.copyFile(source, folder, "testng-suite"); //NOI18N
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-project-ant-ui
@Messages({"# {0} - file location", "FileChooserAccessory_no_such_file=Cannot copy nonexistent path {0} to libraries folder."})
private void copyFiles(List<File> files, FileObject newRoot) throws IOException {
List<File> fs = new ArrayList<File>();
for (File file : files) {
FileObject fo = FileUtil.toFileObject(file);
if (fo == null) {
throw Exceptions.attachLocalizedMessage(new FileNotFoundException(file.toString()), FileChooserAccessory_no_such_file(file));
}
FileObject newFO;
if (fo.isFolder()) {
newFO = copyFolderRecursively(fo, newRoot);
} else {
FileObject foExists = newRoot.getFileObject(fo.getName(), fo.getExt());
if (foExists != null) {
foExists.delete();
}
newFO = FileUtil.copyFile(fo, newRoot, fo.getName(), fo.getExt());
}
fs.add(FileUtil.toFile(newFO));
}
copiedRelativeFiles = getRelativeFiles(fs);
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-j2eeserver
private void copyFolder(FileObject source, FileObject dest) throws IOException {
assert source.isFolder() : "Source is not a folder"; // NOI18N
assert dest.isFolder() : "Source is not a folder"; // NOI18N
for (FileObject child : source.getChildren()) {
if (child.isFolder()) {
FileObject created = FileUtil.createFolder(dest, child.getNameExt());
copyFolder(child, created);
} else {
FileUtil.copyFile(child, dest, child.getName(), child.getExt());
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject
private static void doCopy(Project original, FileObject from, FileObject toParent) throws IOException {
if (!VisibilityQuery.getDefault().isVisible(from)) {
//Do not copy invisible files/folders.
return ;
}
if (!original.getProjectDirectory().equals(FileOwnerQuery.getOwner(from).getProjectDirectory())) {
return ;
}
//#109580
if (SharabilityQuery.getSharability(from) == SharabilityQuery.Sharability.NOT_SHARABLE) {
return;
}
if (from.isFolder()) {
FileObject copy = toParent.createFolder(from.getNameExt());
for (FileObject kid : from.getChildren()) {
doCopy(original, kid, copy);
}
} else {
assert from.isData();
FileObject target = FileUtil.copyFile(from, toParent, from.getName(), from.getExt());
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Copies content of one folder into another.
* @param source source folder
* @param target target folder
* @exception IOException if it fails
*/
private static void copyContent (FileObject source, FileObject target) throws IOException {
FileObject[] srcArr = source.getChildren ();
copyAttrs (source, target);//added
for (int i = 0; i < srcArr.length; i++) {
FileObject child = srcArr[i];
if (MultiFileSystem.isMaskFile (child) ) continue;
if (target.getFileObject (child.getName (), child.getExt ()) == null) {
if (child.isData ()) {
FileObject fo = FileUtil.copyFile (child, target, child.getName (), child.getExt ());
if (fo != null) copyAttrs (child, fo);
} else {
FileObject targetChild = target.createFolder (child.getName ());
copyContent (child, targetChild);
}
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-project-ant-ui
@Override public void run() throws IOException {
assert sourceFolder.isFolder() : sourceFolder;
assert destination.isFolder() : destination;
FileObject destinationSubFolder = destination.getFileObject(sourceFolder.getName());
if (destinationSubFolder == null) {
destinationSubFolder = destination.createFolder(sourceFolder.getName());
}
for (FileObject fo : sourceFolder.getChildren()) {
if (fo.isFolder()) {
copyFolderRecursively(fo, destinationSubFolder);
} else {
FileObject foExists = destinationSubFolder.getFileObject(fo.getName(), fo.getExt());
if (foExists != null) {
foExists.delete();
}
FileUtil.copyFile(fo, destinationSubFolder, fo.getName(), fo.getExt());
}
}
}
});
内容来源于网络,如有侵权,请联系作者删除!