当前位置: 首页>>代码示例>>Java>>正文


Java File.toURI方法代码示例

本文整理汇总了Java中java.io.File.toURI方法的典型用法代码示例。如果您正苦于以下问题:Java File.toURI方法的具体用法?Java File.toURI怎么用?Java File.toURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.toURI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: zip

import java.io.File; //导入方法依赖的package包/类
public static void zip(File directory, final File zipfile) throws IOException {
  final URI base = directory.toURI();
  final Deque<File> queue = new LinkedList<>();
  queue.push(directory);
  try (final OutputStream out = new FileOutputStream(zipfile)) {
    final ZipOutputStream zout = new ZipOutputStream(out);
    while (!queue.isEmpty()) {
      directory = queue.pop();
      for (final File kid : directory.listFiles()) {
        String name = base.relativize(kid.toURI()).getPath();
        if (kid.isDirectory()) {
          queue.push(kid);
          name = name.endsWith("/") ? name : name + "/";
          zout.putNextEntry(new ZipEntry(name));
        } else {
          zout.putNextEntry(new ZipEntry(name));
          StreamUtilities.copy(kid, zout);
          zout.closeEntry();
        }
      }
    }
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:24,代码来源:CompressionUtilities.java

示例2: getTargetPlatformLocalGitRepositoryLocation

import java.io.File; //导入方法依赖的package包/类
/**
 * Returns with the URI pointing to the local git repository root location for storing and retrieving N4JS
 * definition files for the npm installation process.
 *
 * @return the URI pointing to the local git repository location for the N4JSD files in the file system.
 */
default URI getTargetPlatformLocalGitRepositoryLocation() {
	if (null == getTargetPlatformInstallLocation()) {
		final String message = "Target platform install location was not specified.";
		final NullPointerException exception = new NullPointerException(message);
		LOGGER.error(message, exception);
		exception.printStackTrace(); // This if for the HLC as it swallows the actual stack trace.
		throw exception;
	}
	final File installLocation = new File(getTargetPlatformInstallLocation());
	checkState(installLocation.isDirectory(), "Cannot locate target platform install location: " + installLocation);
	// The local git repository should be a sibling folder of the install location.
	File parentFile = installLocation.getParentFile();
	if (null == parentFile || !parentFile.exists() || !parentFile.isDirectory()) {
		LOGGER.warn("Cannot get parent folder of the target platform install location: " + parentFile + ".");
		LOGGER.warn("Falling back to install location: " + installLocation + ".");
		parentFile = installLocation;
	}
	final File gitRoot = new File(parentFile, getGitRepositoryName());
	if (!gitRoot.exists()) {
		checkState(gitRoot.mkdir(), "Error while creating local git repository folder for target platform.");
	}
	checkState(gitRoot.isDirectory(),
			"Cannot locate local git repository folder in target platform install location.");
	return gitRoot.toURI();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:32,代码来源:TargetPlatformInstallLocationProvider.java

示例3: failOnCloseError

import java.io.File; //导入方法依赖的package包/类
@Test
public void failOnCloseError() throws IOException {
  File inFile = File.createTempFile("TestCopyListingIn", null);
  inFile.deleteOnExit();
  File outFile = File.createTempFile("TestCopyListingOut", null);
  outFile.deleteOnExit();
  Path source = new Path(inFile.toURI());

  Exception expectedEx = new IOException("boom");
  SequenceFile.Writer writer = mock(SequenceFile.Writer.class);
  doThrow(expectedEx).when(writer).close();

  SimpleCopyListing listing = new SimpleCopyListing(CONFIG, CREDENTIALS);
  Exception actualEx = null;
  try {
    listing.doBuildListing(writer, options(source, outFile.toURI()));
  } catch (Exception e) {
    actualEx = e;
  }
  Assert.assertNotNull("close writer didn't fail", actualEx);
  Assert.assertEquals(expectedEx, actualEx);
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:23,代码来源:SimpleCopyListingTest.java

示例4: testFailOnCloseError

import java.io.File; //导入方法依赖的package包/类
@Test
public void testFailOnCloseError() throws IOException {
  File inFile = File.createTempFile("TestCopyListingIn", null);
  inFile.deleteOnExit();
  File outFile = File.createTempFile("TestCopyListingOut", null);
  outFile.deleteOnExit();
  List<Path> srcs = new ArrayList<Path>();
  srcs.add(new Path(inFile.toURI()));
  
  Exception expectedEx = new IOException("boom");
  SequenceFile.Writer writer = mock(SequenceFile.Writer.class);
  doThrow(expectedEx).when(writer).close();
  
  SimpleCopyListing listing = new SimpleCopyListing(getConf(), CREDENTIALS);
  DistCpOptions options = new DistCpOptions(srcs, new Path(outFile.toURI()));
  Exception actualEx = null;
  try {
    listing.doBuildListing(writer, options);
  } catch (Exception e) {
    actualEx = e;
  }
  Assert.assertNotNull("close writer didn't fail", actualEx);
  Assert.assertEquals(expectedEx, actualEx);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestCopyListing.java

示例5: main

import java.io.File; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
        JavaFileObject sibling =
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
            .iterator().next();
        JavaFileObject classFile =  fm.getJavaFileForOutput(CLASS_OUTPUT,
                                                            "foo.bar.baz.Test",
                                                            CLASS,
                                                            sibling);
        File file = new File("Test.class").getAbsoluteFile();
        if (!classFile.toUri().equals(file.toURI()))
            throw new AssertionError("Expected " + file.toURI() + ", got " +
                                     classFile.toUri());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Sibling.java

示例6: checkFiles

import java.io.File; //导入方法依赖的package包/类
protected void checkFiles(File dir, Set<String> expectFiles) {
    Set<File> files = new HashSet<File>();
    listFiles(dir, files);
    Set<String> foundFiles = new HashSet<String>();
    URI dirURI = dir.toURI();
    for (File f: files)
        foundFiles.add(dirURI.relativize(f.toURI()).getPath());
    checkFiles(foundFiles, expectFiles, dir);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:APITest.java

示例7: zip

import java.io.File; //导入方法依赖的package包/类
public static void zip(File directory, File zipfile) throws IOException
{
    URI base = directory.toURI();
    Deque<File> queue = new LinkedList<File>();
    queue.push(directory);
    OutputStream out = new FileOutputStream(zipfile);
    Closeable res = null;
    try
    {
        ZipOutputStream zout = new ZipOutputStream(out);
        res = zout;
        while (!queue.isEmpty())
        {
            directory = queue.pop();
            for (File kid : directory.listFiles())
            {
                String name = base.relativize(kid.toURI()).getPath();
                if (kid.isDirectory())
                {
                    queue.push(kid);
                    name = name.endsWith("/") ? name : name + "/";
                    zout.putNextEntry(new ZipEntry(name));
                } else
                {
                    zout.putNextEntry(new ZipEntry(name));
                    Files.copy(kid, zout);
                    zout.closeEntry();
                }
            }
        }
    } finally
    {
        res.close();
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:36,代码来源:ZipperUtil.java

示例8: main

import java.io.File; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:PrintCrashTest.java

示例9: testURIParam

import java.io.File; //导入方法依赖的package包/类
private int testURIParam(int testnum) throws Exception {
    // get an instance of JavaPolicy from SUN and have it read from the URL

    File file = new File(System.getProperty("test.src", "."),
                            "GetInstance.policyURL");
    URI uri = file.toURI();
    Policy p = Policy.getInstance(JAVA_POLICY, new URIParameter(uri));

    doTest(p, testnum++);
    Policy.setPolicy(p);
    doTestSM(testnum++);

    return testnum;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:GetInstance.java

示例10: addCatalog

import java.io.File; //导入方法依赖的package包/类
/**
 * Adds a new catalog file.Use created or existed resolver to parse new catalog file.
 *
 * @param catalogFile
 * @throws java.io.IOException
 */
public void addCatalog(File catalogFile) throws IOException {
    URI newUri = catalogFile.toURI();
    if (!catalogUrls.contains(newUri)) {
        catalogUrls.add(newUri);
    }
    entityResolver = CatalogUtil.getCatalog(entityResolver, catalogFile, catalogUrls);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Options.java

示例11: getAppConfigFileUri

import java.io.File; //导入方法依赖的package包/类
/**
 * Returns the file that will be read when resetting application configuration
 * settings. This file may or may not actually exist.
 * @return the file that will be read when resetting application configuration
 *         settings.
 */
private URI getAppConfigFileUri() throws URISyntaxException {
    File configFile = new File("./appconfig.xml");
    if (configFile.exists()) {
        return configFile.toURI();
    } else {
        return getClass().getResource("/com/esri/vehiclecommander/resources/appconfig.xml").toURI();
    }
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:15,代码来源:AppConfigController.java

示例12: getPathRelativeToWC

import java.io.File; //导入方法依赖的package包/类
protected String getPathRelativeToWC(File file) {
    URI wcURI = getWC().toURI();
    URI fileURI = file.toURI();
    URI relativePathURI = wcURI.relativize(fileURI);
    if (relativePathURI == fileURI) {
        throw new IllegalArgumentException(
                "The given file is not in the working directory.");
    }
    return relativePathURI.getPath();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AbstractSvnTestCase.java

示例13: scanDirectory

import java.io.File; //导入方法依赖的package包/类
@Override protected void scanDirectory(ClassLoader loader, File root) throws IOException {
  URI base = root.toURI();
  for (File entry : Files.fileTreeTraverser().preOrderTraversal(root)) {
    String resourceName = new File(base.relativize(entry.toURI()).getPath()).getPath();
    resources.add(resourceName);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ClassPathTest.java

示例14: testImport94Table

import java.io.File; //导入方法依赖的package包/类
/**
 * Test import data from 0.94 exported file
 * @throws Exception
 */
@Test
public void testImport94Table() throws Exception {
  final String name = "exportedTableIn94Format";
  URL url = TestImportExport.class.getResource(name);
  File f = new File(url.toURI());
  if (!f.exists()) {
    LOG.warn("FAILED TO FIND " + f + "; skipping out on test");
    return;
  }
  assertTrue(f.exists());
  LOG.info("FILE=" + f);
  Path importPath = new Path(f.toURI());
  FileSystem fs = FileSystem.get(UTIL.getConfiguration());
  fs.copyFromLocalFile(importPath, new Path(FQ_OUTPUT_DIR + Path.SEPARATOR + name));
  String IMPORT_TABLE = name;
  try (Table t = UTIL.createTable(TableName.valueOf(IMPORT_TABLE), Bytes.toBytes("f1"), 3);) {
    String[] args = new String[] {
        "-Dhbase.import.version=0.94" ,
        IMPORT_TABLE, FQ_OUTPUT_DIR
    };
    assertTrue(runImport(args));
    /* exportedTableIn94Format contains 5 rows
    ROW         COLUMN+CELL
    r1          column=f1:c1, timestamp=1383766761171, value=val1
    r2          column=f1:c1, timestamp=1383766771642, value=val2
    r3          column=f1:c1, timestamp=1383766777615, value=val3
    r4          column=f1:c1, timestamp=1383766785146, value=val4
    r5          column=f1:c1, timestamp=1383766791506, value=val5
    */
   assertEquals(5, UTIL.countRows(t));
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:37,代码来源:TestImportExport.java

示例15: Song

import java.io.File; //导入方法依赖的package包/类
public Song(String name, String title, int track, String album, String length, String itemIdentifier) {
    this.name = name;
    this.title = title;
    this.track = track;
    this.album = album;
    this.length = length;
    this.itemIdentifier = itemIdentifier;

    try {
        File temp = new File(String.format("items/%s/%s.mp3", itemIdentifier, title));
        filePath = temp.toURI();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}
 
开发者ID:zacwood9,项目名称:attics,代码行数:16,代码来源:Song.java


注:本文中的java.io.File.toURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。