本文整理了Java中java.io.File.<init>()
方法的一些代码示例,展示了File.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.<init>()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:<init>
[英]Constructs a new file using the specified directory and name.
[中]使用指定的目录和名称构造新文件。
代码示例来源:origin: iluwatar/java-design-patterns
/**
* @return True, if the file given exists, false otherwise.
*/
public boolean fileExists() {
return new File(this.fileName).exists();
}
代码示例来源:origin: stackoverflow.com
File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) {
// do something
}
代码示例来源:origin: stackoverflow.com
// create a File object for the parent directory
File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// have the object build the directory structure, if needed.
wallpaperDirectory.mkdirs();
// create a File object for the output file
File outputFile = new File(wallpaperDirectory, filename);
// now attach the OutputStream to the file object, instead of a String representation
FileOutputStream fos = new FileOutputStream(outputFile);
代码示例来源:origin: libgdx/libgdx
private void copyAndReplace (String outputDir, Project project, Map<String, String> values) {
File out = new File(outputDir);
if (!out.exists() && !out.mkdirs()) {
throw new RuntimeException("Couldn't create output directory '" + out.getAbsolutePath() + "'");
}
for (ProjectFile file : project.files) {
copyFile(file, out, values);
}
}
代码示例来源:origin: apache/incubator-dubbo
resolveFile = System.getProperty("dubbo.resolve.file");
if (StringUtils.isEmpty(resolveFile)) {
File userResolveFile = new File(new File(System.getProperty("user.home")), "dubbo-resolve.properties");
if (userResolveFile.exists()) {
resolveFile = userResolveFile.getAbsolutePath();
try (FileInputStream fis = new FileInputStream(new File(resolveFile))) {
properties.load(fis);
} catch (IOException e) {
代码示例来源:origin: stanfordnlp/CoreNLP
private void save(String path) throws IOException {
System.out.print("Saving classifier to " + path + "... ");
// make sure the directory specified by path exists
int lastSlash = path.lastIndexOf(File.separator);
if (lastSlash > 0) {
File dir = new File(path.substring(0, lastSlash));
if (! dir.exists())
dir.mkdirs();
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
out.writeObject(weights);
out.writeObject(featureIndex);
out.writeObject(labelIndex);
out.close();
System.out.println("done.");
}
代码示例来源:origin: androidannotations/androidannotations
private File ensureOutputDirectory() {
File outputDir = new File(OUTPUT_DIRECTORY);
if (!outputDir.exists()) {
outputDir.mkdirs();
}
return outputDir;
}
代码示例来源:origin: stackoverflow.com
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/PhysicsSketchpad";
File dir = new File(file_path);
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, "sketchpad" + pad.t_id + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
代码示例来源:origin: stackoverflow.com
File theDir = new File("new folder");
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + directoryName);
boolean result = false;
try{
theDir.mkdir();
result = true;
}
catch(SecurityException se){
//handle it
}
if(result) {
System.out.println("DIR created");
}
}
代码示例来源:origin: stackoverflow.com
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
myImage.setImageBitmap(myBitmap);
}
代码示例来源:origin: apache/incubator-druid
@Before
public void setUp() throws IOException
{
cgroupDir = temporaryFolder.newFolder();
procDir = temporaryFolder.newFolder();
TestUtils.setUpCgroups(procDir, cgroupDir);
cpuacctDir = new File(
cgroupDir,
"cpu,cpuacct/system.slice/some.service/f12ba7e0-fa16-462e-bb9d-652ccc27f0ee"
);
Assert.assertTrue((cpuacctDir.isDirectory() && cpuacctDir.exists()) || cpuacctDir.mkdirs());
TestUtils.copyResource("/cpuacct.usage_all", new File(cpuacctDir, "cpuacct.usage_all"));
}
代码示例来源:origin: eclipse-vertx/vert.x
private File setupFile(String testDir, String fileName, String content) throws Exception {
File file = new File(testDir, fileName);
if (file.exists()) {
file.delete();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
out.write(content);
out.close();
return file;
}
代码示例来源:origin: stackoverflow.com
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
_bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
//you can create a new file name "test.jpg" in sdcard folder.
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg");
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
// remember close de FileOutput
fo.close();
代码示例来源:origin: square/okhttp
public void run() throws Exception {
File file = new File("README.md");
Request request = new Request.Builder()
.url("https://api.github.com/markdown/raw")
.post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
}
代码示例来源:origin: Tencent/tinker
private static void setRunningLocation(CliMain m) {
mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
try {
mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (mRunningLocation.endsWith(".jar")) {
mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1);
}
File f = new File(mRunningLocation);
mRunningLocation = f.getAbsolutePath();
}
代码示例来源:origin: alibaba/druid
private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
InputStream inStream = null;
File file = new File(filePath);
if (file.exists()) {
inStream = new FileInputStream(file);
} else {
inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
}
return inStream;
}
}
代码示例来源:origin: stackoverflow.com
File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
代码示例来源:origin: stackoverflow.com
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");
FileOutputStream f = new FileOutputStream(file);
...
代码示例来源:origin: skylot/jadx
private Object test(Object obj) {
File file = new File("r");
FileOutputStream output = null;
try {
output = new FileOutputStream(file);
if (obj.equals("a")) {
return new Object();
} else {
return null;
}
} catch (IOException e) {
System.out.println("Exception");
return null;
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
// Ignored
}
}
file.delete();
}
}
}
代码示例来源:origin: skylot/jadx
private Object test(Object obj) {
FileOutputStream output = null;
try {
output = new FileOutputStream(new File("f"));
return new Object();
} catch (FileNotFoundException e) {
System.out.println("Exception");
return null;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!