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


Java FileUtil類代碼示例

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


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

示例1: getVirtualFile

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private void getVirtualFile(String sourceName, VirtualFile virtualFile[], String compileRoot)
        throws Exception {
    if (!ArrayUtils.isEmpty(virtualFile)) {
        VirtualFile arr$[] = virtualFile;
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; i$++) {
            VirtualFile vf = arr$[i$];
            String srcName;
            if (StringUtils.indexOf(vf.toString(), "$") != -1)
                srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.indexOf(vf.toString(), "$"));
            else
                srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.length(vf.toString()) - 6);
            String dstName = StringUtils.substring(sourceName, 0, StringUtils.length(sourceName) - 5);
            if (StringUtils.equals(srcName, dstName)) {
                String outRoot = (new StringBuilder()).append(StringUtils.substring(compileRoot, 0, StringUtils.lastIndexOf(compileRoot, "/"))).append("/out").toString();
                String packagePath = StringUtils.substring(vf.getPath(), StringUtils.length(compileRoot), StringUtils.length(vf.getPath()));
                File s = new File(vf.getPath());
                File t = new File((new StringBuilder()).append(outRoot).append(packagePath).toString());
                FileUtil.copy(s, t);
            }
            if (!ArrayUtils.isEmpty(virtualFile))
                getVirtualFile(sourceName, vf.getChildren(), compileRoot);
        }

    }
}
 
開發者ID:serical,項目名稱:patcher,代碼行數:27,代碼來源:ClassesExportAction.java

示例2: findProject

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
@Nullable
private Project findProject(String file) {
  LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  ProjectLocator projectLocator = ProjectLocator.getInstance();
  AtomicReference<Project> ret = new AtomicReference<>();
  FileUtil.processFilesRecursively(
      new File(file),
      (f) -> {
        VirtualFile vf = localFileSystem.findFileByIoFile(f);
        if (vf != null) {
          ret.set(projectLocator.guessProjectForFile(vf));
          return false;
        }
        return true;
      });
  return ret.get();
}
 
開發者ID:google,項目名稱:ijaas,代碼行數:18,代碼來源:JavaGetImportCandidatesHandler.java

示例3: parseScripts

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
public static final List<String> parseScripts(File f) {
    List<String> list = new ArrayList<>();
    if(!f.exists()) {
        return list;
    }

    try {
        JsonObject result = new Gson().fromJson(FileUtil.loadFile(f, "UTF-8"), JsonObject.class);
        JsonObject scripts = result.getAsJsonObject("scripts");
        if(scripts == null) {
            return list;// Fix NPE when there is an empty or no scripts package.json file
        }
        for (Map.Entry<String, JsonElement> obj:
                scripts.entrySet()) {
            list.add(obj.getKey());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return list;
}
 
開發者ID:beansoftapp,項目名稱:react-native-console,代碼行數:23,代碼來源:NPMParser.java

示例4: findAntResult

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private void findAntResult(final Map<Project, AntGenResult> resultMap) {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        final HybrisProjectSettings hybrisProjectSettings =
            HybrisProjectSettingsComponent.getInstance(project).getState();

        if (!hybrisProjectSettings.isHybrisProject()) {
            continue;
        }

        final File file = new File(project.getBasePath() + "/" + hybrisProjectSettings.getHybrisDirectory() + "/temp/ant.ser");
        if (file.exists()) {
            AntGenResult result = null;
            try (
                final FileInputStream fileIn = new FileInputStream(file);
                final ObjectInputStream in = new ObjectInputStream(fileIn)
            ) {
                result = (AntGenResult) in.readObject();
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
            FileUtil.delete(file);
            resultMap.put(project, result);
            return;
        }
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:27,代碼來源:HybrisAntBuildListener.java

示例5: removeAllFiles

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
@Override
public void removeAllFiles(@NotNull final Collection<File> files) throws IOException {
    Validate.notNull(files);

    if (files.isEmpty()) {
        return;
    }

    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();

    for (File file : files) {
        final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file);

        if (null != virtualFile) {
            ApplicationManager.getApplication().runWriteAction(new RemoveFileComputable(virtualFile));
        } else {
            FileUtil.delete(file);
        }
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:21,代碼來源:DefaultVirtualFileSystemService.java

示例6: transformTestFile

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private static void transformTestFile(@NotNull Project project, int toSubtaskIndex, VirtualFile taskDir) {

    String subtaskTestFileName = getTestFileName(project, toSubtaskIndex);
    if (subtaskTestFileName == null) {
      return;
    }
    String nameWithoutExtension = FileUtil.getNameWithoutExtension(subtaskTestFileName);
    String extension = FileUtilRt.getExtension(subtaskTestFileName);
    VirtualFile subtaskTestFile = taskDir.findChild(nameWithoutExtension + ".txt");
    if (subtaskTestFile != null) {
      ApplicationManager.getApplication().runWriteAction(() -> {
        try {
          subtaskTestFile.rename(project, nameWithoutExtension + "." + extension);
        }
        catch (IOException e) {
          LOG.error(e);
        }
      });
    }
  }
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:21,代碼來源:StudySubtaskUtils.java

示例7: getTaskDescription

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
/**
 * @param wrap if true, text will be wrapped with ancillary information (e.g. to display latex)
 */
public String getTaskDescription(boolean wrap) {
  String fileName = getTaskDescriptionName();
  //TODO: replace this with simple get after implementing migration for taskTexts
  Map.Entry<String, String> entry =
    EntryStream.of(taskTexts).findFirst(e -> FileUtil.getNameWithoutExtension(e.getKey()).equals(fileName)).orElse(null);
  if (entry == null) {
    return null;
  }
  String taskText = entry.getValue();
  if (!wrap) {
    return taskText;
  }
  taskText = StudyUtils.wrapTextToDisplayLatex(StudyUtils.convertToHtml(taskText));
  if (getLesson().getCourse().isAdaptive()) {
    taskText = EduAdaptiveStepicConnector.wrapAdaptiveCourseText(this, taskText);
  }
  return taskText;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:22,代碼來源:Task.java

示例8: updateTestHelper

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private void updateTestHelper() {
  StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().runWriteAction(() -> {
    final VirtualFile baseDir = myProject.getBaseDir();
    if (baseDir == null) {
      return;
    }
    final VirtualFile testHelper = baseDir.findChild(EduNames.TEST_HELPER);
    if (testHelper != null) {
      StudyUtils.deleteFile(testHelper);
    }
    final FileTemplate template =
      FileTemplateManager.getInstance(myProject).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER));
    try {
      final PsiDirectory projectDir = PsiManager.getInstance(myProject).findDirectory(baseDir);
      if (projectDir != null) {
        FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir);
      }
    }
    catch (Exception e) {
      LOG.warn("Failed to create new test helper");
    }
  }));
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:24,代碼來源:StudyTaskManager.java

示例9: getSubtaskIndex

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
public static int getSubtaskIndex(@NotNull Project project, @NotNull VirtualFile file) {
  String fileName = file.getName();
  String name = FileUtil.getNameWithoutExtension(fileName);
  if (!isTestsFile(project, file)) {
    return -1;
  }
  if (!name.contains(EduNames.SUBTASK_MARKER)) {
    return 0;
  }
  int markerIndex = name.indexOf(EduNames.SUBTASK_MARKER);
  String index = name.substring(markerIndex + EduNames.SUBTASK_MARKER.length());
  if (index.isEmpty()) {
    return -1;
  }
  try {
    return Integer.valueOf(index);
  }
  catch (NumberFormatException e) {
    return -1;
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:22,代碼來源:CCUtils.java

示例10: transformFiles

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private static void transformFiles(Course course, Project project) {
  List<VirtualFile> files = getAllAnswerTaskFiles(course, project);
  for (VirtualFile answerFile : files) {
    ApplicationManager.getApplication().runWriteAction(() -> {
      String answerName = answerFile.getName();
      String nameWithoutExtension = FileUtil.getNameWithoutExtension(answerName);
      String name = FileUtil.getNameWithoutExtension(nameWithoutExtension) + "." + FileUtilRt.getExtension(answerName);
      VirtualFile parent = answerFile.getParent();
      VirtualFile file = parent.findChild(name);
      try {
        if (file != null) {
          file.delete(CCProjectComponent.class);
        }
        VirtualFile windowsDescrFile = parent.findChild(FileUtil.getNameWithoutExtension(name) + EduNames.WINDOWS_POSTFIX);
        if (windowsDescrFile != null) {
          windowsDescrFile.delete(CCProjectComponent.class);
        }
        answerFile.rename(CCProjectComponent.class, name);
      }
      catch (IOException e) {
        LOG.error(e);
      }
    });
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:26,代碼來源:CCProjectComponent.java

示例11: getAllAnswerTaskFiles

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private static List<VirtualFile> getAllAnswerTaskFiles(@NotNull Course course, @NotNull Project project) {
  List<VirtualFile> result = new ArrayList<>();
  for (Lesson lesson : course.getLessons()) {
    for (Task task : lesson.getTaskList()) {
      for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name);
        String taskPath = FileUtil.join(project.getBasePath(), EduNames.LESSON + lesson.getIndex(), EduNames.TASK + task.getIndex());
        VirtualFile taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, answerName));
        if (taskFile == null) {
          taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, EduNames.SRC, answerName));
        }
        if (taskFile != null) {
          result.add(taskFile);
        }
      }
    }
  }
  return result;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:21,代碼來源:CCProjectComponent.java

示例12: CreateCourseArchivePanel

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
public CreateCourseArchivePanel(@NotNull final Project project, CreateCourseArchiveDialog dlg, String name) {
  setLayout(new BorderLayout());
  add(myPanel, BorderLayout.CENTER);
  myErrorIcon.setIcon(AllIcons.Actions.Lightning);
  setState(false);
  myDlg = dlg;
  String sanitizedName = FileUtil.sanitizeFileName(name);
  myNameField.setText(sanitizedName.startsWith("_") ? EduNames.COURSE : sanitizedName);
  myLocationField.setText(project.getBasePath());
  FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myLocationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor);
  myLocationField.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      String location = myLocationField.getText();
      File file = new File(location);
      if (!file.exists() || !file.isDirectory()) {
        myDlg.enableOKAction(false);
        setError("Invalid location");
      }
      myDlg.enableOKAction(true);
    }
  });
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:25,代碼來源:CreateCourseArchivePanel.java

示例13: doStepOptionsCreationTest

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
private static StepicWrappers.StepOptions doStepOptionsCreationTest(String fileName) throws IOException {
  String responseString =
    FileUtil.loadFile(new File(getTestDataPath(), fileName));
  StepicWrappers.StepSource stepSource =
    EduStepicClient.deserializeStepicResponse(StepicWrappers.StepContainer.class, responseString).steps.get(0);
  StepicWrappers.StepOptions options = stepSource.block.options;
  List<TaskFile> files = options.files;
  assertTrue("Wrong number of task files", files.size() == 1);
  List<AnswerPlaceholder> placeholders = files.get(0).getAnswerPlaceholders();
  assertTrue("Wrong number of placeholders", placeholders.size() == 1);
  Map<Integer, AnswerPlaceholderSubtaskInfo> infos = placeholders.get(0).getSubtaskInfos();
  assertNotNull(infos);
  assertEquals(Collections.singletonList("Type your name here."), infos.get(0).getHints());
  assertEquals("Liana", infos.get(0).getPossibleAnswer());
  return options;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:17,代碼來源:StudyStepicFormatTest.java

示例14: getTestsFile

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
@Nullable
@Override
protected VirtualFile getTestsFile() {
  String testFileName = EduJavaPluginConfigurator.TEST_JAVA;
  if (myTask instanceof TaskWithSubtasks) {
    int activeSubtaskIndex = ((TaskWithSubtasks) myTask).getActiveSubtaskIndex();
    testFileName = FileUtil.getNameWithoutExtension(testFileName) + EduNames.SUBTASK_MARKER + activeSubtaskIndex + "." + FileUtilRt.getExtension(EduJavaPluginConfigurator.TEST_JAVA);
  }
  VirtualFile taskDir = myTask.getTaskDir(myProject);
  if (taskDir == null) {
    return null;
  }
  VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
  if (srcDir != null) {
    taskDir = srcDir;
  }
  VirtualFile virtualFile = taskDir.findChild(testFileName);
  if (virtualFile != null) {
    return virtualFile;
  }
  return null;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:23,代碼來源:EduJavaPyCharmTaskChecker.java

示例15: createModule

import com.intellij.openapi.util.io.FileUtil; //導入依賴的package包/類
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  Project project = baseModule.getProject();
  EduProjectGenerator generator = new EduProjectGenerator();
  if (myCourse == null) {
    File courseRoot = StudyUtils.getBundledCourseRoot(DEFAULT_COURSE_NAME, EduKotlinKoansModuleBuilder.class);
    final Course course = generator.addLocalCourse(FileUtil.join(courseRoot.getPath(), DEFAULT_COURSE_NAME));
    if (course == null) {
      LOG.info("Failed to find course " + DEFAULT_COURSE_NAME);
      return baseModule;
    }
  }
  myCourse.setLanguage("kotlin");
  EduModuleBuilderUtils.createCourseFromCourseInfo(moduleModel, project, generator, myCourse, getModuleFileDirectory());
  return baseModule;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:19,代碼來源:EduKotlinKoansModuleBuilder.java


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