本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.createIfDoesntExist方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.createIfDoesntExist方法的具体用法?Java FileUtil.createIfDoesntExist怎么用?Java FileUtil.createIfDoesntExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.createIfDoesntExist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNotSignApk
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static String createNotSignApk(File apkFile, String tempPath, String apkNameWithoutExtension)
throws FileNotFoundException {
String tempApkPath = tempPath + File.separator + apkNameWithoutExtension + "-unsigned.apk";
File tempApk = new File(tempApkPath);
FileUtil.createIfDoesntExist(tempApk);
//delete signature
boolean success = ZipHelper.update(new FileInputStream(apkFile), new FileOutputStream(tempApk),
new HashMap<>(0));
if (!success) {
String message = "create tempApk failed, please try again";
NotificationHelper.error(message);
throw new RuntimeException(message);
}
return tempApkPath;
}
示例2: saveVersion
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void saveVersion() {
final Boolean differs = myVersionDiffers;
if (differs == null || differs) {
try {
FileUtil.createIfDoesntExist(myVersionFile);
final DataOutputStream os = new DataOutputStream(new FileOutputStream(myVersionFile));
try {
os.writeInt(VERSION);
myVersionDiffers = Boolean.FALSE;
}
finally {
os.close();
}
}
catch (IOException ignored) {
}
}
}
示例3: copyWithFiltering
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void copyWithFiltering(File file, File outputFile) throws IOException {
final String encoding = myEncodingConfig != null? myEncodingConfig.getEncoding(file) : null;
PrintWriter writer;
try {
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
}
catch (FileNotFoundException e) {
FileUtil.createIfDoesntExist(outputFile);
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
}
try {
final byte[] bytes = FileUtil.loadFileBytes(file);
final String text = encoding != null? new String(bytes, encoding) : new String(bytes);
doFilterText(text, getDelimitersPattern(), getProperties(), null, writer);
}
finally {
writer.close();
}
}
示例4: saveDetectors
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void saveDetectors() {
final File file = getDetectorsRegistryFile();
FileUtil.createIfDoesntExist(file);
try {
DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
try {
output.writeInt(REGISTRY_VERSION);
output.writeInt(myDetectorsVersion);
final FrameworkDetector[] detectors = FrameworkDetector.EP_NAME.getExtensions();
output.writeInt(detectors.length);
for (FrameworkDetector detector : detectors) {
output.writeUTF(detector.getDetectorId());
output.writeInt(myDetectorIds.get(detector.getDetectorId()));
output.writeInt(detector.getDetectorVersion());
}
}
finally {
output.close();
}
}
catch (IOException e) {
LOG.info(e);
}
}
示例5: testNonExistentDirectoryRoot
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testNonExistentDirectoryRoot() throws IOException {
String dir = getAbsolutePath("d");
JpsArtifact a = addArtifact(root().dirCopy(dir));
buildArtifacts(a);
assertEmptyOutput(a);
buildAllAndAssertUpToDate();
FileUtil.createIfDoesntExist(new File(dir, "a.txt"));
buildArtifacts(a);
assertOutput(a, fs().file("a.txt"));
buildAllAndAssertUpToDate();
delete(dir);
buildArtifacts(a);
assertEmptyOutput(a);
buildAllAndAssertUpToDate();
}
示例6: restoreFileFromCachedContent
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static boolean restoreFileFromCachedContent(final VirtualFile parent,
final String name,
final String revision,
boolean makeReadOnly) {
try {
final File cachedContentFile = getCachedContentFile(parent, name, revision);
if (cachedContentFile == null) return false;
final byte[] content = FileUtil.loadFileBytes(cachedContentFile);
final File file = new File(parent.getPath(), name);
FileUtil.createIfDoesntExist(file);
if (!file.canWrite() && !file.setWritable(true)) return false;
FileUtil.writeToFile(file, content);
if (makeReadOnly && !file.setWritable(false)) return false;
return file.setLastModified(cachedContentFile.lastModified());
}
catch (IOException e) {
LOG.error(e);
return false;
}
}
示例7: storeLines
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void storeLines(List<String> lines, File file) throws IOException {
String separator = getLineSeparatorFor(file);
FileUtil.createIfDoesntExist(file);
if (!file.canWrite()) {
new FileReadOnlyHandler().setFileReadOnly(file, false);
}
Writer writer =
new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), CvsApplicationLevelConfiguration.getCharset());
try {
for (final String line : lines) {
writer.write(line);
writer.write(separator);
}
}
finally {
writer.close();
}
}
示例8: saveRegisteredIndices
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void saveRegisteredIndices(@NotNull Collection<ID<?, ?>> ids) {
final File file = getRegisteredIndicesFile();
try {
FileUtil.createIfDoesntExist(file);
final DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
try {
os.writeInt(ids.size());
for (ID<?, ?> id : ids) {
IOUtil.writeString(id.toString(), os);
}
}
finally {
os.close();
}
}
catch (IOException ignored) {
}
}
示例9: writeFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void writeFile(File file, int length, InputStream inputStream) throws IOException {
if (length == 0) {
FileUtil.createIfDoesntExist(file);
return;
}
final OutputStream fileOutputStream = new FileOutputStream(file);
try {
final byte[] chunk = new byte[BUFFER_SIZE];
int size = length;
while (size > 0) {
final int bytesToRead = Math.min(size, chunk.length);
final int bytesRead = inputStream.read(chunk, 0, bytesToRead);
if (bytesRead < 0) {
break;
}
size -= bytesRead;
fileOutputStream.write(chunk, 0, bytesRead);
}
}
finally {
try {
fileOutputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
示例10: copyFilesFillingEditorInfos
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@NotNull
protected Map<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(@NotNull VirtualFile fromDir,
@NotNull VirtualFile toDir,
@NotNull String... relativePaths) throws IOException {
Map<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
List<OutputStream> streamsToClose = new ArrayList<OutputStream>();
for (String relativePath : relativePaths) {
if (relativePath.startsWith("/")) {
relativePath = relativePath.substring(1);
}
final VirtualFile fromFile = fromDir.findFileByRelativePath(relativePath);
assertNotNull(fromDir.getPath() + "/" + relativePath, fromFile);
VirtualFile toFile = toDir.findFileByRelativePath(relativePath);
if (toFile == null) {
final File file = new File(toDir.getPath(), relativePath);
FileUtil.createIfDoesntExist(file);
toFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
assertNotNull(file.getCanonicalPath(), toFile);
}
toFile.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, FileUtil.toSystemDependentName(fromFile.getPath()));
editorInfos.put(toFile, copyContent(fromFile, toFile, streamsToClose));
}
for(int i = streamsToClose.size() -1; i >= 0 ; --i) {
streamsToClose.get(i).close();
}
return editorInfos;
}
示例11: createProjectFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
/**
* Creates a file using the given path.
*
* @param path the path of the file to create. It is relative to {@link #getRootDir()}.
* @return the created file.
*/
@NotNull
public File createProjectFile(@NotNull String path) {
File file = new File(myRootDir, path);
FileUtil.createIfDoesntExist(file);
return file;
}
示例12: storePassword
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void storePassword(String stringConfiguration, String scrambledPassword) throws IOException {
final File passFile = getPassFile();
FileUtil.createIfDoesntExist(passFile);
final List<String> lines = CvsFileUtil.readLinesFrom(passFile);
lines.add(stringConfiguration + " " + scrambledPassword);
CvsFileUtil.storeLines(lines, passFile);
}
示例13: saveDotProjectFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void saveDotProjectFile(@NotNull Module module, @NotNull String storageRoot) throws IOException {
try {
Document doc;
if (ModuleType.get(module) instanceof JavaModuleType) {
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.project.xml"));
}
else {
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.empty.project.xml"));
}
doc.getRootElement().getChild(EclipseXml.NAME_TAG).setText(module.getName());
final File projectFile = new File(storageRoot, EclipseXml.PROJECT_FILE);
if (!FileUtil.createIfDoesntExist(projectFile)) {
return;
}
EclipseJDOMUtil.output(doc.getRootElement(), projectFile, module.getProject());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(projectFile.getPath()));
}
});
}
catch (JDOMException e) {
LOG.error(e);
}
}
示例14: generateDictionary
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void generateDictionary(final Project project, final Collection<VirtualFile> folderPaths, final String outFile,
final ProgressIndicator progressIndicator) {
final HashSet<String> seenNames = new HashSet<String>();
// Collect stuff
for (VirtualFile folder : folderPaths) {
progressIndicator.setText2("Scanning folder: " + folder.getPath());
final PsiManager manager = PsiManager.getInstance(project);
processFolder(seenNames, manager, folder);
}
if (seenNames.isEmpty()) {
LOG.info(" No new words was found.");
return;
}
final StringBuilder builder = new StringBuilder();
// Sort names
final ArrayList<String> names = new ArrayList<String>(seenNames);
Collections.sort(names);
for (String name : names) {
if (builder.length() > 0){
builder.append("\n");
}
builder.append(name);
}
try {
final File dictionaryFile = new File(outFile);
FileUtil.createIfDoesntExist(dictionaryFile);
final FileWriter writer = new FileWriter(dictionaryFile.getPath());
try {
writer.write(builder.toString());
}
finally {
writer.close();
}
}
catch (IOException e) {
LOG.error(e);
}
}
示例15: readLinesFrom
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static List<String> readLinesFrom(File file, String cvsRootToSkip) throws IOException {
FileUtil.createIfDoesntExist(file);
ArrayList<String> result = new ArrayList<String>();
BufferedReader reader =
new BufferedReader(new InputStreamReader(new FileInputStream(file), CvsApplicationLevelConfiguration.getCharset()));
try {
String line;
while ((line = reader.readLine()) != null) {
if (!line.contains(cvsRootToSkip)) result.add(line);
}
return result;
} finally {
reader.close();
}
}