本文整理匯總了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);
}
}
示例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());
}
示例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);
}
}
示例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;
}
示例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);
}
示例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());
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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?");
}
}
}
示例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);
}
示例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);
}
}