发布网友 发布时间:2022-04-22 17:37
共1个回答
热心网友 时间:2023-05-05 09:58
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class base64 {
public static String getWAVString(){
File fi = new File("click.wav");
if (!fi.exists())
return "";
byte[] data = null;
try{
InputStream is = new FileInputStream(fi);
data = new byte[is.available()];
is.read(data);
is.close();
}catch(Exception ex){
ex.printStackTrace();
}
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
public static void getWAV(){
BASE64Decoder decoder = new BASE64Decoder();
try{
byte[] data = decoder.decodeBuffer(WAVString);
/*for(int i=0 ;i<data.length;i++){
if (data[i] < 0) {
data[i] += 256;
}
}*/
OutputStream out = new FileOutputStream("click_BASE64.wav");
out.write(data);
out.flush();
out.close();
}catch(Exception ex){
}
}
public static void main(String[] args){
WAVString = getWAVString();
try{
FileWriter out = new FileWriter("Click_BASE64String.txt");
out.write(WAVString);
out.flush();
out.close();
}catch(Exception ex){
}
getWAV();
}
private static String WAVString;
}