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


Java Files.copy方法代码示例

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


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

示例1: copyJavaBase

import java.nio.file.Files; //导入方法依赖的package包/类
private void copyJavaBase(Path targetDir) throws IOException {
    FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
    Path javaBase = jrt.getPath("modules", "java.base");

    if (!Files.exists(javaBase)) {
        throw new AssertionError("No java.base?");
    }

    Path javaBaseClasses = targetDir.resolve("java.base");

    for (Path clazz : tb.findFiles("class", javaBase)) {
        Path target = javaBaseClasses.resolve(javaBase.relativize(clazz).toString());
        Files.createDirectories(target.getParent());
        Files.copy(clazz, target);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IncubatingTest.java

示例2: setUp

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Creates regular/modular jar files for TestClient and TestClassLoader.
 */
private static void setUp() throws Exception {

    // Generate regular jar files for TestClient and TestClassLoader
    JarUtils.createJarFile(CL_JAR, TEST_CLASSES,
                           "cl/TestClassLoader.class");
    JarUtils.createJarFile(C_JAR, TEST_CLASSES,
                           "c/TestClient.class");
    // Generate modular jar files for TestClient and TestClassLoader with
    // their corresponding ModuleDescriptor.
    Files.copy(CL_JAR, MCL_JAR,
            StandardCopyOption.REPLACE_EXISTING);
    updateModuleDescr(MCL_JAR, ModuleDescriptor.newModule("mcl")
            .exports("cl").requires("java.base").build());
    Files.copy(C_JAR, MC_JAR,
            StandardCopyOption.REPLACE_EXISTING);
    updateModuleDescr(MC_JAR, ModuleDescriptor.newModule("mc")
            .exports("c").requires("java.base").requires("mcl").build());
    Files.copy(C_JAR, AMC_JAR,
            StandardCopyOption.REPLACE_EXISTING);
    updateModuleDescr(AMC_JAR, ModuleDescriptor.newModule("mc")
            .exports("c").requires("java.base").requires("cl").build());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ClassLoaderTest.java

示例3: gzipBase64

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Gzips the input then base-64 it.
 *
 * @param path the input data file, as an instance of {@link Path}
 * @return the compressed output, as a String
 */
private static String gzipBase64(Path path) {
  try {
    long size = Files.size(path) / 4 + 1;
    int initialSize = size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(initialSize)) {
      try (OutputStream baseos = Base64.getEncoder().wrap(baos)) {
        try (GZIPOutputStream zos = new GZIPOutputStream(baseos)) {
          Files.copy(path, zos);
        }
      }
      return baos.toString("ISO-8859-1");  // base-64 bytes are ASCII, so this is optimal
    }
  } catch (IOException ex) {
    throw new UncheckedIOException("Failed to gzip base-64 content", ex);
  }
}
 
开发者ID:OpenGamma,项目名称:JavaSDK,代码行数:23,代码来源:PortfolioDataFile.java

示例4: prepareDotProject

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * For Test-mocks copies over "_project"-files to ".project" files and supplies a delete-on-exit shutdown hook for
 * them.
 *
 * @param projectSourceFolder
 *            folder potentially containing "_project", that is a potential workspace-project
 * @returns <code>true</code> if a .project file was created. <code>false</code> otherwise.
 */
public static boolean prepareDotProject(File projectSourceFolder) {
	File dotProject = new File(projectSourceFolder, ".project");
	File dotProjectTemplate = new File(projectSourceFolder, "_project");

	if (dotProject.exists()) {
		if (!dotProjectTemplate.exists()) {
			// err if giving direct .project files cluttering the developers workspace
			throw new IllegalArgumentException("proband must rename the '.project' file to '_project'");
		} // else assume crashed VM leftover of .project, will be overwritten below.
	}
	if (dotProjectTemplate.exists()) {
		try {
			Files.copy(dotProjectTemplate.toPath(), dotProject.toPath(), StandardCopyOption.REPLACE_EXISTING);
		} catch (IOException e) {
			throw new IllegalStateException("unable to prepare .project-file", e);
		}
		dotProject.deleteOnExit();
		return true;
	}

	return false;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:31,代码来源:ProjectUtils.java

示例5: copyWorkingToOutFile

import java.nio.file.Files; //导入方法依赖的package包/类
private void copyWorkingToOutFile(AudioInfo audioInfo, Path srcFolder, Path destFolder) {
	String filename = audioInfo.getTargetName();
	int duration = audioInfo.getDuration();
	String targetName = filename.replaceFirst("^(.*)([.][^.]*)$", "$1");
	String targetNameExt = filename.replaceFirst("^(.*)([.][^.]*)$", "$2");
	String outFilenname = targetName + "_D"+duration+targetNameExt;
	Path src = srcFolder.resolve(filename);
	Path dest = destFolder.resolve(outFilenname);
	if (!Files.exists(dest)) {
		try {
			Files.copy(src, dest);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	audioInfo.setTargetName(outFilenname);
}
 
开发者ID:ferenc-hechler,项目名称:RollenspielAlexaSkill,代码行数:18,代码来源:SoloRoleplayGame6Test.java

示例6: createTestAnalysis

import java.nio.file.Files; //导入方法依赖的package包/类
private static TestAnalysis createTestAnalysis() throws IOException {
    InputStream empty_dict = KuromojiAnalysisTests.class.getResourceAsStream("empty_user_dict.txt");
    InputStream dict = KuromojiAnalysisTests.class.getResourceAsStream("user_dict.txt");
    Path home = createTempDir();
    Path config = home.resolve("config");
    Files.createDirectory(config);
    Files.copy(empty_dict, config.resolve("empty_user_dict.txt"));
    Files.copy(dict, config.resolve("user_dict.txt"));
    String json = "/org/elasticsearch/index/analysis/kuromoji_analysis.json";

    Settings settings = Settings.builder()
        .loadFromStream(json, KuromojiAnalysisTests.class.getResourceAsStream(json))
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
        .build();
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), home).build();
    return createTestAnalysis(new Index("test", "_na_"), nodeSettings, settings, new AnalysisKuromojiPlugin());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:KuromojiAnalysisTests.java

示例7: generateBackupCopy

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Generates a copy of the database and lets
 * the user choose where to save it
 */
private void generateBackupCopy() {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save Backup Copy");
    fileChooser.setInitialDirectory(
            new File(System.getProperty("user.home"))
    );
    fileChooser.setInitialFileName("Backup Copy " + LocalDate.now() + ".db");
    FileChooser.ExtensionFilter databaseExtensionFilter =
            new FileChooser.ExtensionFilter(
                    "DB - Database (.db)", "*.db");
    fileChooser.getExtensionFilters().add(databaseExtensionFilter);
    fileChooser.setSelectedExtensionFilter(databaseExtensionFilter);
    File backupFile = fileChooser.showSaveDialog(currentStage);

    if (backupFile != null) {
        try {
            File theDatabase = new File(DatabaseHelper.DATABASE_PATH_NAME);
            if (!theDatabase.exists()) {
                DatabaseHelper.createDatabase();
            }
            Files.copy(theDatabase.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:kwilliams3,项目名称:Recordian,代码行数:32,代码来源:BackupTabController.java

示例8: visitFile

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
Files.copy(file,
    targetPath.resolve(sourcePath.relativize(file)));
return FileVisitResult.CONTINUE;
}
 
开发者ID:PioBeat,项目名称:GravSupport,代码行数:8,代码来源:CopyFileVisitor.java

示例9: copyFile

import java.nio.file.Files; //导入方法依赖的package包/类
public static void copyFile(File sourceFile, File destFile) throws IOException {
    Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.COPY_ATTRIBUTES);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:5,代码来源:AppUtil.java

示例10: copyNpmFiles

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Copy 'package.json', 'package-lock.json' or '.npmrc' files from application base dir to .idea/jfrog/npm/.
 * @param source the application base dir
 * @param dest path to the project '.idea/jfrog/npm/'
 */
private static void copyNpmFiles(Path source, Path dest) throws IOException {
    Files.createDirectories(dest);
    for (String npmFile : NPM_FILES) {
        Path sourceNpmFile = source.resolve(npmFile);
        if (Files.exists(sourceNpmFile)) {
            Files.copy(sourceNpmFile, dest.resolve(npmFile), REPLACE_EXISTING, COPY_ATTRIBUTES);
        }
    }
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:15,代码来源:NpmScanManager.java

示例11: setUp

import java.nio.file.Files; //导入方法依赖的package包/类
@BeforeTest
public void setUp() throws IOException {
    // Create test directory inside scratch
    testWorkDir = Paths.get(System.getProperty("user.dir", "."));
    // Save its URL
    testWorkDirUrl = testWorkDir.toUri().toURL();
    // Get test source directory path
    testSrcDir = Paths.get(System.getProperty("test.src", "."));
    // Get path of xjc result folder
    xjcResultDir = testWorkDir.resolve(TEST_PACKAGE);
    // Copy schema document file to scratch directory
    Files.copy(testSrcDir.resolve(XSD_FILENAME), testWorkDir.resolve(XSD_FILENAME), REPLACE_EXISTING);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:JaxbMarshallTest.java

示例12: setup

import java.nio.file.Files; //导入方法依赖的package包/类
@BeforeTest
public void setup() throws Exception {
    boolean compiled = CompilerUtils.compile(SRC_DIR.resolve(TEST_MODULE),
                                             MODS_DIR.resolve(TEST_MODULE));
    assertTrue(compiled, "module " + TEST_MODULE + " did not compile");

    // add the class and a resource to the current working directory
    Path file = Paths.get("jdk/test/Main.class");
    Files.createDirectories(file.getParent());
    Files.copy(MODS_DIR.resolve(TEST_MODULE).resolve(file), file);

    Path res = Paths.get("jdk/test/res.properties");
    Files.createFile(res);

    ToolProvider jartool = ToolProvider.findFirst("jar").orElseThrow(
        () -> new RuntimeException("jar tool not found")
    );

    Path jarfile = LIB_DIR.resolve("m.jar");
    Files.createDirectories(LIB_DIR);
    assertTrue(jartool.run(System.out, System.err, "cfe",
                           jarfile.toString(), TEST_MAIN,
                           file.toString()) == 0);

    Path manifest = LIB_DIR.resolve("manifest");
    try (BufferedWriter writer = Files.newBufferedWriter(manifest)) {
        writer.write("CLASS-PATH: lib/m.jar");
    }
    jarfile = LIB_DIR.resolve("m1.jar");
    assertTrue(jartool.run(System.out, System.err, "cfme",
                           jarfile.toString(), manifest.toString(), TEST_MAIN,
                           file.toString()) == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:JavaClassPathTest.java

示例13: Test_For_Config

import java.nio.file.Files; //导入方法依赖的package包/类
public void Test_For_Config() {
    if (!getDataFolder().exists()){
        getDataFolder().mkdir();
        getLogger().info("Created new folder for the plugin.");
    }
    File file = new File(getDataFolder(), "config.yml");
    if (!file.exists()) {
        try (InputStream in = getResourceAsStream("config.yml")) {
            Files.copy(in, file.toPath());
            getLogger().info("Created new config for the plugin.");
        } catch (IOException e) {
            getLogger().severe("Error: Could not create a config, do you have permission?");
        }
    }
}
 
开发者ID:Zambosoe,项目名称:BungeeDisplayName,代码行数:16,代码来源:Main.java

示例14: download

import java.nio.file.Files; //导入方法依赖的package包/类
/**
    * Simple copy of file to download on Servlet output stream.
    */
   @Override
   public void download(HttpServletRequest request, File file, OutputStream outputStream) throws IOException {

if (! file.exists()) {
    throw new FileNotFoundException("File does not exist: " + file.getName());
}

Files.copy(file.toPath(), outputStream);

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:14,代码来源:DefaultBlobDownloadConfigurator.java

示例15: copyResource

import java.nio.file.Files; //导入方法依赖的package包/类
public static void copyResource(Path outputDir, String resourceName) {
	try {
		// Create the directory if required
		if (!Files.exists(outputDir.getParent())) {
			Files.createDirectories(outputDir.getParent());
		}

		InputStream is = WriterSupport.class.getClassLoader().getResourceAsStream(resourceName);
		Files.copy(is, outputDir, StandardCopyOption.REPLACE_EXISTING);
	} catch (IOException e) {
		LOGGER.info("Failed to copy resource " + resourceName);

	}
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:15,代码来源:WriterSupport.java


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