1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import java.io.*;
class coupe
{
public static void main(String args[]) throws IOException
{
int i=0;
//image ou fichier à découper
String cible="c:/Pics/image0.jpeg";
File f1=new File(cible);
//fichiers résultat
File f2=null;
//fixer la taille de chaque bloc
byte []b=new byte[4*1024];
//boucle de découpage
if(f1.canRead())
{
FileInputStream sf1=new FileInputStream(f1);
while((sf1.read(b))!=-1)
{
String s=cible.substring(0,((cible.length())-5));
f2=new File(s+i+".jpeg");
FileOutputStream sf2=new FileOutputStream(f2);
if(f2.canWrite())
{
sf2.write(b);
sf2.close();
}
i++;
}
}
}
} |
Partager