Here you can find the source of copyToTempDirectory(final String file)
Parameter | Description |
---|---|
file | a parameter |
private static String copyToTempDirectory(final String file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 InfAI.org/*from w w w .jav a 2 s . c o m*/ * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * *******************************************************************************/ import java.io.*; import java.nio.channels.FileChannel; public class Main { /** * @param file * @return */ private static String copyToTempDirectory(final String file) { try { final String ending = file.substring(file.lastIndexOf('.')); final File tempfile = File.createTempFile("model", ending); copyFile(new File(file), tempfile); return tempfile.getAbsolutePath(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } public static void copyFile(final File in, final File out) throws IOException { final FileChannel inChannel = new FileInputStream(in).getChannel(); final FileChannel outChannel = new FileOutputStream(out).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (final IOException e) { throw e; } finally { if (inChannel != null) { inChannel.close(); } if (outChannel != null) { outChannel.close(); } } } }