package client;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;
/**
* 保存音频数据,pcm
* @author lief
*
*/
public class SaveFile implements Runnable{
private File file=null;
private FileOutputStream fos = null;
private BufferedOutputStream bos = null;
//private FileWriter fileWrite;
private String path = "voice.txt";
private String logpath = "log.txt";
private InputStream in = null;
// private byte[] buffer = new byte[80000];
private Logger logger = Logger.getLogger(logpath);
private Thread thread;
public SaveFile(InputStream in){
this.in=in;
try{file=new File(path);
file.createNewFile();
/*if(!file.exists()){
file.createNewFile();
}*/
}catch(IOException e){
logger.info("文件创建失败");
}
}
@Override
public void run() {
// TODO Auto-generated method stub
byte[] buffer = new byte[80000];
while(thread != null)
{
try {
fos=new FileOutputStream(path,true);
bos=new BufferedOutputStream(fos);
in.read(buffer);
bos.write(buffer);
bos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void start() {
// TODO Auto-generated method stub
thread=new Thread(this);
thread.start();
}
}
转载于:https://blog.51cto.com/5232047/1333180