Netwerkschijfer
Gebruiker
- Lid geworden
- 17 jun 2009
- Berichten
- 6
Is het mogenlijk om alle files die in een treeset staan op je computer te laten plaatsen in een map? In de C map ofzow of in de D map.
Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
TreeSet<File> files = jouw TreeSet;
public void writefiles() {
int x = 0;
for (File file : files) {
x++;
try {
copyFile(file, "C:\\folder\\file"+x+".ext");
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void copyFile(File oldFile, String newFileLocation) throws IOException {
DataOutputStream outputStream = null;
DataInputStream inputStream = null;
try {
File file = new File(newFileLocation);
File folder = file.getParentFile();
if(folder.mkdirs()) {
if (file.createNewFile()) {
if (oldFile.isFile()) {
inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(oldFile)));
outputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
byte[] buf = new byte[1024];
int i = 0;
while ((i = inputStream.read(buf)) != -1) {
System.out.println("working");
outputStream.write(buf, 0, i);
}
}
else {
System.out.println("no file found!");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
if (inputStream != null) inputStream.close();
if (outputStream != null) outputStream.close();
}
}
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.