當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.rename方法代碼示例

本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.rename方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.rename方法的具體用法?Java FileUtil.rename怎麽用?Java FileUtil.rename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.util.io.FileUtil的用法示例。


在下文中一共展示了FileUtil.rename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: backup

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private boolean backup(final File file, final Project project, GenerationOptions genOptions, List<File> filesToRefresh) {
  if (!genOptions.backupPreviouslyGeneratedFiles || !file.exists()) {
    return true;
  }
  final String path = file.getPath();
  final int extensionIndex = path.lastIndexOf(".");
  final String extension = path.substring(extensionIndex, path.length());
  //noinspection HardCodedStringLiteral
  final String backupPath = path.substring(0, extensionIndex) +
                            "_" +
                            new Date(file.lastModified()).toString().replaceAll("\\s+", "_").replaceAll(":", "-") +
                            extension;
  final File backupFile = new File(backupPath);
  boolean ok;
  try {
    FileUtil.rename(file, backupFile);
    ok = true;
  }
  catch (IOException e) {
    Messages.showErrorDialog(project, CompilerBundle.message("error.ant.files.backup.failed", path),
                             CompilerBundle.message("generate.ant.build.title"));
    ok = false;
  }
  filesToRefresh.add(backupFile);
  return ok;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:GenerateAntBuildAction.java

示例2: testFileCaseChange

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void testFileCaseChange() throws Exception {
  if (SystemInfo.isFileSystemCaseSensitive) {
    System.err.println("Ignored: case-insensitive FS required");
    return;
  }

  File topDir = createTestDir(myTempDirectory, "topDir");
  File testFile = createTestFile(topDir, "file.txt", "123");
  refresh(topDir);

  LocalFileSystem.WatchRequest request = watch(topDir);
  try {
    myAccept = true;
    File newFile = new File(testFile.getParent(), StringUtil.capitalize(testFile.getName()));
    FileUtil.rename(testFile, newFile);
    assertEvent(VFilePropertyChangeEvent.class, newFile.getPath());
  }
  finally {
    unwatch(request);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:FileWatcherTest.java

示例3: moveToDir

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static List<Pair<File, DownloadableFileDescription>> moveToDir(List<Pair<File, DownloadableFileDescription>> downloadedFiles,
                                                                       final File targetDir) throws IOException {
  FileUtil.createDirectory(targetDir);
  List<Pair<File, DownloadableFileDescription>> result = new ArrayList<Pair<File, DownloadableFileDescription>>();
  for (Pair<File, DownloadableFileDescription> pair : downloadedFiles) {
    final DownloadableFileDescription description = pair.getSecond();
    final String fileName = description.generateFileName(new Condition<String>() {
      @Override
      public boolean value(String s) {
        return !new File(targetDir, s).exists();
      }
    });
    final File toFile = new File(targetDir, fileName);
    FileUtil.rename(pair.getFirst(), toFile);
    result.add(Pair.create(toFile, description));
  }
  return result;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:FileDownloaderImpl.java

示例4: testApplyingWithCaseChangedNames

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Test
public void testApplyingWithCaseChangedNames() throws Exception {
  FileUtil.rename(new File(myOlderDir, "Readme.txt"), new File(myOlderDir, "README.txt"));

  Patch patch = PatchFileCreator.create(myPatchSpec, myFile, TEST_UI);

  assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:9,代碼來源:PatchFileCreatorTest.java

示例5: setUp

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void setUp() throws Exception {
  super.setUp();
  myOlderDir = getDataDir();
  myNewerDir = getTempFile("newDir");
  FileUtil.copyDir(myOlderDir, myNewerDir);

  FileUtil.delete(new File(myNewerDir, "bin/idea.bat"));
  FileUtil.writeToFile(new File(myNewerDir, "Readme.txt"), "hello".getBytes());
  File newFile = new File(myNewerDir, "newDir/newFile.txt");
  newFile.getParentFile().mkdirs();
  newFile.createNewFile();
  FileUtil.writeToFile(newFile, "hello".getBytes());

  FileUtil.delete(new File(myOlderDir, "lib/annotations_changed.jar"));
  FileUtil.delete(new File(myNewerDir, "lib/annotations.jar"));
  FileUtil.rename(new File(myNewerDir, "lib/annotations_changed.jar"),
                  new File(myNewerDir, "lib/annotations.jar"));

  FileUtil.delete(new File(myOlderDir, "lib/bootstrap_deleted.jar"));
  FileUtil.delete(new File(myNewerDir, "lib/bootstrap.jar"));
  FileUtil.rename(new File(myNewerDir, "lib/bootstrap_deleted.jar"),
                  new File(myNewerDir, "lib/bootstrap.jar"));

  FileUtil.delete(new File(myOlderDir, "lib/boot2_changed_with_unchanged_content.jar"));
  FileUtil.delete(new File(myNewerDir, "lib/boot2.jar"));
  FileUtil.rename(new File(myNewerDir, "lib/boot2_changed_with_unchanged_content.jar"),
                  new File(myNewerDir, "lib/boot2.jar"));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:PatchTestCase.java

示例6: testFileCaseChange

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void testFileCaseChange() throws Exception {
  if (SystemInfo.isFileSystemCaseSensitive) {
    System.err.println("Ignored: case-insensitive FS required");
    return;
  }

  File top = createTempDirectory(false);
  File file = IoTestUtil.createTestFile(top, "file.txt", "test");

  VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top);
  assertNotNull(topDir);
  VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file);
  assertNotNull(sourceFile);

  String newName = StringUtil.capitalize(file.getName());
  FileUtil.rename(file, newName);
  topDir.refresh(false, true);
  assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());

  topDir.getChildren();
  newName = newName.toLowerCase(Locale.ENGLISH);
  FileUtil.rename(file, newName);
  topDir.refresh(false, true);
  assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:LocalFileSystemTest.java

示例7: rollbackChanges

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void rollbackChanges() throws IOException {
  try {
    FileUtil.delete(mySourceFile);
  }
  finally {
    try {
      FileUtil.rename(myTempFile, mySourceFile);
    }
    finally {
      FileUtil.delete(myTempFile);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:ActionWithTempFile.java

示例8: moveAllFiles

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static void moveAllFiles(@NotNull File from, @NotNull File to, @NotNull Collection<File> newFiles) throws IOException {
  if (from.isFile()) {
    FileUtil.rename(from, to);
    newFiles.add(to);
  }
  else {
    final File[] children = from.listFiles();

    if (children != null) {
      for (File child : children) {
        moveAllFiles(child, new File(to, child.getName()), newFiles);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:AndroidCommonUtils.java

示例9: renameLocalFile

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void renameLocalFile(FileObject fileObject, ICvsFileSystem cvsFileSystem, String newFileName) {
  final File originalFile = cvsFileSystem.getLocalFileSystem().getFile(fileObject);
  final File targetFile = new File(originalFile.getParentFile(), newFileName);
  try {
    FileUtil.rename(originalFile, targetFile);
  }
  catch (IOException e) {
    //ignore
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:LocalFileWriter.java

示例10: testWhenAuthCredsNoInConfig

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void testWhenAuthCredsNoInConfig() throws Exception {
  final TestListener listener = new TestListener(mySynchObject);
  myAuthenticationManager.addListener(listener);
  final SavedOnceListener savedOnceListener = new SavedOnceListener();
  myAuthenticationManager.addListener(savedOnceListener);

  final File config = new File(myConfiguration.getConfigurationDirectory(), "config");
  final String contents = FileUtil.loadFile(config);
  final String auth = "[auth]";
  final int idx = contents.indexOf(auth);
  Assert.assertTrue(idx != -1);
  final String newContents = contents.substring(0, idx + auth.length()) + "\nstore-auth-creds=no\n" + contents.substring(idx + auth.length());

  final File oldConfig = new File(myConfiguration.getConfigurationDirectory(), "config_old");
  FileUtil.rename(config, oldConfig);
  try {
    config.createNewFile();
    FileUtil.appendToFile(config, newContents);

    final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");

    final SVNException[] exception = new SVNException[1];
    final Boolean[] result = new Boolean[1];
    synchronousBackground(() -> {
      try {
        listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
        listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));

        commonScheme(url, false, null);
        Assert.assertEquals(2, listener.getCnt());
        Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
        myTestInteraction.reset();
        savedOnceListener.assertForAwt();
        savedOnceListener.reset();

        SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
        listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
        listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
        commonScheme(url, false, null);
        Assert.assertEquals(4, listener.getCnt());
        Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
      }
      catch (SVNException e) {
        exception[0] = e;
      }
      result[0] = true;
    });

    Assert.assertTrue(result[0]);
    Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
    Assert.assertEquals(4, listener.getCnt());
    listener.assertForAwt();
    savedOnceListener.assertForAwt();
    savedOnceListener.assertNotSaved(url, ISVNAuthenticationManager.PASSWORD);

    if (exception[0] != null) {
      throw exception[0];
    }
  } finally {
    FileUtil.delete(config);
    FileUtil.rename(oldConfig, config);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:64,代碼來源:SvnAuthenticationTest.java

示例11: testWhenPassSaveNoInServers

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void testWhenPassSaveNoInServers() throws Exception {
  final TestListener listener = new TestListener(mySynchObject);
  myAuthenticationManager.addListener(listener);
  final SavedOnceListener savedOnceListener = new SavedOnceListener();
  myAuthenticationManager.addListener(savedOnceListener);

  final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers");

  final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
  FileUtil.copy(servers, oldServers);
  try {
    FileUtil.appendToFile(servers, "\nstore-passwords=no\n");

    final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");

    final SVNException[] exception = new SVNException[1];
    final Boolean[] result = new Boolean[1];
    synchronousBackground(new Runnable() {
      @Override
      public void run() {
        try {
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.request));
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.interactive, url, Type.request));
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.without_pasword_save));

          commonScheme(url, false, null);
          Assert.assertEquals(3, listener.getCnt());
          Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
          myTestInteraction.reset();
          savedOnceListener.assertForAwt();
          savedOnceListener.reset();

          SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.request));
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.interactive, url, Type.request));
          listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.without_pasword_save));
          commonScheme(url, false, null);
          Assert.assertEquals(6, listener.getCnt());
          Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
        }
        catch (SVNException e) {
          exception[0] = e;
        }
        result[0] = true;
      }
    });

    Assert.assertTrue(result[0]);
    Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
    Assert.assertEquals(6, listener.getCnt());
    listener.assertForAwt();
    savedOnceListener.assertForAwt();
    savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);

    if (exception[0] != null) {
      throw exception[0];
    }
  } finally {
    FileUtil.delete(servers);
    FileUtil.rename(oldServers, servers);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:63,代碼來源:SvnAuthenticationTest.java

示例12: renameFile

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void renameFile(Object requestor, @NotNull final VirtualFile file, @NotNull final String newName) throws IOException {
  if (!VirtualFile.isValidName(newName)) {
    throw new IOException(VfsBundle.message("file.invalid.name.error", newName));
  }

  boolean sameName = !isCaseSensitive() && newName.equalsIgnoreCase(file.getName());

  if (!file.exists()) {
    throw new IOException(VfsBundle.message("vfs.file.not.exist.error", file.getPath()));
  }
  VirtualFile parent = file.getParent();
  if (parent == null) {
    throw new IOException(VfsBundle.message("cannot.rename.root.directory", file.getPath()));
  }
  if (!sameName && parent.findChild(newName) != null) {
    throw new IOException(VfsBundle.message("vfs.target.already.exists.error", parent.getPath() + "/" + newName));
  }

  File ioFile = convertToIOFile(file);
  if (!ioFile.exists()) {
    throw new FileNotFoundException(VfsBundle.message("file.not.exist.error", ioFile.getPath()));
  }
  File ioTarget = new File(convertToIOFile(parent), newName);
  if (!sameName && ioTarget.exists()) {
    throw new IOException(VfsBundle.message("target.already.exists.error", ioTarget.getPath()));
  }

  if (!auxRename(file, newName)) {
    if (!FileUtil.rename(ioFile, newName)) {
      throw new IOException(VfsBundle.message("rename.failed.error", ioFile.getPath(), newName));
    }
  }

  auxNotifyCompleted(new ThrowableConsumer<LocalFileOperationsHandler, IOException>() {
    @Override
    public void consume(LocalFileOperationsHandler handler) throws IOException {
      handler.rename(file, newName);
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:42,代碼來源:LocalFileSystemBase.java

示例13: finished

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void finished(@Nullable final FileType fileType) {
  final File localIOFile;

  synchronized (myLock) {
    LOG.debug("Downloading finished, size = " + myLocalFile.length() + ", file type=" + (fileType != null ? fileType.getName() : "null"));
    if (fileType != null) {
      String fileName = myLocalFile.getName();
      int dot = fileName.lastIndexOf('.');
      String extension = fileType.getDefaultExtension();
      if (dot == -1 || !extension.regionMatches(true, 0, fileName, dot + 1, extension.length())) {
        File newFile = FileUtil.findSequentNonexistentFile(myLocalFile.getParentFile(), fileName, extension);
        try {
          FileUtil.rename(myLocalFile, newFile);
          myLocalFile = newFile;
        }
        catch (IOException e) {
          LOG.debug(e);
        }
      }
    }

    localIOFile = myLocalFile;
  }

  VirtualFile localFile = new WriteAction<VirtualFile>() {
    @Override
    protected void run(@NotNull final Result<VirtualFile> result) {
      final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(localIOFile);
      if (file != null) {
        file.refresh(false, false);
      }
      result.setResult(file);
    }
  }.execute().getResultObject();
  LOG.assertTrue(localFile != null, "Virtual local file not found for " + localIOFile.getAbsolutePath());
  LOG.debug("Virtual local file: " + localFile + ", size = " + localFile.getLength());
  synchronized (myLock) {
    myLocalVirtualFile = localFile;
    myPrevLocalFile = null;
    myState = RemoteFileState.DOWNLOADED;
    myErrorMessage = null;
  }
  for (FileDownloadingListener listener : myListeners) {
    listener.fileDownloaded(localFile);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:48,代碼來源:RemoteFileInfoImpl.java

示例14: testSavedAndReadUnix

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void testSavedAndReadUnix() throws Exception {
  if (SystemInfo.isWindows) return;

  final TestListener listener = new TestListener(mySynchObject);
  myAuthenticationManager.addListener(listener);
  final SavedOnceListener savedOnceListener = new SavedOnceListener();
  myAuthenticationManager.addListener(savedOnceListener);

  final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");

  final SVNException[] exception = new SVNException[1];
  final Boolean[] result = new Boolean[1];

  final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers");
  final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
  FileUtil.copy(servers, oldServers);
  try {
    FileUtil.appendToFile(servers, "\nstore-plaintext-passwords=yes\n");

    synchronousBackground(() -> {
      try {
        listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
        listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
        listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save));

        commonScheme(url, false, null);
        Assert.assertEquals(3, listener.getCnt());
        //long start = System.currentTimeMillis();
        //waitListenerStep(start, listener, 3);

        SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
        listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
        commonScheme(url, false, null);
        //start = System.currentTimeMillis();
        //waitListenerStep(start, listener, 4);
        Assert.assertEquals(4, listener.getCnt());
      }
      catch (SVNException e) {
        exception[0] = e;
      }
      result[0] = true;
    });
  } finally {
    FileUtil.delete(servers);
    FileUtil.rename(oldServers, servers);
  }

  Assert.assertTrue(result[0]);
  myTestInteraction.assertNothing();
  Assert.assertEquals(4, listener.getCnt());
  listener.assertForAwt();
  savedOnceListener.assertForAwt();

  savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);

  if (exception[0] != null) {
    throw exception[0];
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:60,代碼來源:SvnAuthenticationTest.java

示例15: init

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void init() throws IOException {
  myTempFile = FileUtil.createTempFile(TMP_PREFIX, TMP_SUFFIX);
  FileUtil.delete(myTempFile);
  FileUtil.rename(mySourceFile, myTempFile);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:ActionWithTempFile.java


注:本文中的com.intellij.openapi.util.io.FileUtil.rename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。