本文整理了Java中com.intellij.openapi.util.io.FileUtil.writeToFile()
方法的一些代码示例,展示了FileUtil.writeToFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.writeToFile()
方法的具体详情如下:
包路径:com.intellij.openapi.util.io.FileUtil
类名称:FileUtil
方法名:writeToFile
暂无
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private static boolean prepareFile(@NotNull File file) {
try {
FileUtil.writeToFile(file, new byte[]{0x7F, 'E', 'L', 'F'});
}
catch (IOException e) {
return false;
}
return file.setExecutable(true);
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
additionalCreatedFiles.add(librariesConfigFile);
FileUtil.writeToFile(librariesConfigFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project></project>");
addProjectDirToLibraries(librariesConfigFile, rootElement(librariesConfigFile));
代码示例来源:origin: KronicDeth/intellij-elixir
public String createFile(String relativePath, String text){
try{
File file = new File(getOrCreateProjectDir(), relativePath);
FileUtil.writeToFile(file, text);
return FileUtil.toSystemIndependentName(file.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: KronicDeth/intellij-elixir
protected static void change(String filePath, @Nullable String newContent){
try{
File file = new File(FileUtil.toSystemDependentName(filePath));
assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists());
if(newContent != null){
FileUtil.writeToFile(file, newContent);
}
long oldTimeStamp = FileSystemUtil.lastModified(file);
long time = System.currentTimeMillis();
setLastModified(file, time);
if(FileSystemUtil.lastModified(file) <= oldTimeStamp){
setLastModified(file, time + 1);
long newTimeStamp = FileSystemUtil.lastModified(file);
if(newTimeStamp <= oldTimeStamp){
// Mac OS and som versions of Linux truncates timestamp to nearest second
setLastModified(file, time + 1000);
newTimeStamp = FileSystemUtil.lastModified(file);
assertTrue("Failed to change timestamp for " + file.getAbsolutePath(), newTimeStamp > oldTimeStamp);
}
sleepUntil(newTimeStamp);
}
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: makejavas/EasyCode
/**
* 写入文件内容
* @param file 文件
* @param content 文件内容
* @param append 是否为追加模式
*/
public void write(File file, String content, boolean append) {
try {
FileUtil.writeToFile(file, content, append);
} catch (IOException e) {
ExceptionUtil.rethrow(e);
}
}
}
代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij
/**
* Creates all {@link File files} annotated with {@link TestFile} in the given directory name.
*
* @param directoryName the name of the directory to create the test files in
*/
private void createTestFiles(String directoryName) throws IllegalAccessException, IOException {
for (Field field : getFieldsWithAnnotation(testInstance.getClass(), TestFile.class)) {
field.setAccessible(true);
if (!field.getType().equals(File.class)) {
throw new IllegalArgumentException(
"@TestFile can only annotate fields of type java.io.File");
}
TestFile annotation = field.getAnnotation(TestFile.class);
File directory = FileUtil.createTempDirectory(directoryName, null);
File file = new File(directory, annotation.name());
if (!file.createNewFile()) {
throw new IOException("Can't create file: " + file);
}
if (!annotation.contents().isEmpty()) {
FileUtil.writeToFile(file, annotation.contents());
}
filesToDelete.add(file);
field.set(testInstance, file);
}
}
代码示例来源:origin: Haehnchen/idea-php-toolbox
FileUtil.writeToFile(file, str);
} catch (IOException ignored) {
PhpToolboxApplicationService.LOG.error(String.format("Can not write to '%s' file", file));
代码示例来源:origin: neueda/jetbrains-plugin-graph-database-support
private static synchronized void cleanupNeo4jKnownHosts(Neo4jServerLoader neo4jServerLoader) {
File hostsFile = Config.defaultConfig().trustStrategy().certFile();
try {
if (hostsFile != null && hostsFile.isFile()) {
List<String> lines = FileUtil.loadLines(hostsFile);
List<String> updatedLines = lines.stream()
.filter((line) -> !line.startsWith(neo4jServerLoader.getBoltHost() + ":" + neo4jServerLoader.getBoltPort()))
.filter((line) -> !line.isEmpty())
.collect(Collectors.toList());
FileUtil.writeToFile(hostsFile, String.join(System.lineSeparator(), updatedLines) + System.lineSeparator());
}
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: Camelcade/Perl5-IDEA
private void saveSvgFile(@NotNull final String outSvgFile, @NotNull final ControlFlow flow) throws IOException, ExecutionException {
String dotUtilName = SystemInfoRt.isUnix ? "dot" : "dot.exe";
File dotFullPath = PathEnvironmentVariableUtil.findInPath(dotUtilName);
if (dotFullPath == null) {
throw new FileNotFoundException("Cannot find dot utility in path");
}
File tmpFile = FileUtil.createTempFile("control-flow", ".dot", true);
FileUtil.writeToFile(tmpFile, convertControlFlowToDot(flow));
ExecUtil.execAndGetOutput(new GeneralCommandLine(dotFullPath.getAbsolutePath()).withInput(tmpFile.getAbsoluteFile())
.withParameters("-Tsvg", "-o" + outSvgFile, tmpFile.getAbsolutePath()).withRedirectErrorStream(true));
}
代码示例来源:origin: BashSupport/BashSupport
@NotNull
private PsiFile createTempPsiFile(@NotNull String content) throws IOException {
File tempFile = File.createTempFile("test", ".bash");
FileUtil.writeToFile(tempFile, content);
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(tempFile);
assertNotNull("file " + tempFile.getAbsolutePath() + " not found", vFile);
Assert.assertEquals(BashFileType.BASH_FILE_TYPE, vFile.getFileType());
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vFile);
Assert.assertNotNull(psiFile);
return psiFile;
}
}
代码示例来源:origin: cheptsov/AdvancedExpressionFolding
FileUtil.writeToFile(new File(destinationFileName), cleanContent);
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(destinationFileName);
assertNotNull(file);
代码示例来源:origin: Microsoft/azure-devops-intellij
Debug.println("uniqueString", uniqueString);
final File readme = new File(projectPath, README_FILE);
FileUtil.writeToFile(readme, uniqueString);
Debug.println("readme path", readme.getAbsolutePath());
代码示例来源:origin: Microsoft/azure-devops-intellij
/**
* Adds a new line of text to a file and adds/commits it
*
* @param file
* @param repository
* @param project
* @throws IOException
* @throws IOException
*/
public static void editAndCommitFile(final File file, final git4idea.repo.GitRepository repository, final Project project) throws IOException {
// edits file
final VirtualFile readmeVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
FileUtil.writeToFile(file, "\nnew line", true);
// adds and commits the change
final LocalChangeListImpl localChangeList = LocalChangeListImpl.createEmptyChangeListImpl(project, "TestCommit", "12345");
final ChangeListManagerImpl changeListManager = ChangeListManagerImpl.getInstanceImpl(project);
VcsDirtyScopeManager.getInstance(project).markEverythingDirty();
changeListManager.ensureUpToDate(false);
changeListManager.addUnversionedFiles(localChangeList, ImmutableList.of(readmeVirtualFile));
final Change change = changeListManager.getChange(LocalFileSystem.getInstance().findFileByIoFile(file));
repository.getVcs().getCheckinEnvironment().commit(ImmutableList.of(change), COMMIT_MESSAGE);
}
内容来源于网络,如有侵权,请联系作者删除!