【文件属性】:
文件名称:截取一个文件的一段内容
文件大小:856B
文件格式:TXT
更新时间:2011-12-01 12:41:50
截取文件的一段
例:可截取一个mp3文件中好听的部分
package com.Service;
import java.io.*;
public class FileofCut
{
public FileofCut()
{
}
public void test()
{
try
{
FileInputStream fis = new FileInputStream("F:\\a.mp3");
FileOutputStream fos = new FileOutputStream("F:\\b.mp3");
int size = 256;
int total = 0;
byte [] bs = new byte[size];
int real = fis.read(bs);
while(real > 0)
{
total++;
if(total>=12060&&total<=13800)
{
fos.write(bs,0,real);
}
real = fis.read(bs);
}
System.out.print(total);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String []args)
{
FileofCut fc = new FileofCut();
fc.test();
}
}