Per necessità ho trasformato la classe che mi hai fornito (che quando lavora come classe standalone funziona perfettamente) in metodo ma il compilatore mi ha sollevato tante eccezioni del tipo:Originariamente inviato da Enumaelish
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyerFile {
public static void main(String[] args) {
File pathTo = new File("to.txt");
File pathFrom = new File("from.txt");
try {
FileInputStream inputFile = new FileInputStream(pathFrom);
int bytes = inputFile.available();
System.out.println("Numero di byte: " + bytes);
pathTo.createNewFile();
FileOutputStream outputFile = new FileOutputStream(pathTo);
int readBytes = 0;
while (readBytes <= bytes){
outputFile.write(inputFile.read());
readBytes++;
}
inputFile.close();
outputFile.close();
} catch (FileNotFoundException e) {
System.out.println("Il file: " + pathFrom.toString() + ", non esiste!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Problemi con la lettura dei bytes!");
e.printStackTrace();
}
}
}
Questo codice copia un file (from.txt) su un altro (to.txt)
qualsiasi file... perchè ho usato gli array di Byte![]()
Client.java:36: unreported exception java.io.IOException; must be caught or declared to be thrown
outputFile.close();
^
Dove sto sbagliando visto che il sorgente ha questa struttura:
codice:import ...; public class Client { static boolean CopyerFile(String path, String filename) { // codice tuo riadattato alle mie esigenze } // parte restante dell'applicazione }

Rispondi quotando