Java流的操作使用

来源:互联网 发布:有java基础学python 编辑:程序博客网 时间:2024/05/16 09:46
public static void main(String[] args){
String sss = DataWhitelistsService.class.getResource("/").getPath();
String s2 = sss.substring(0, sss.indexOf("/WEB-INF"));
FileInputStream input = null;
FileOutputStream out = null;
BufferedInputStream bufferedInput =  null;
BufferedOutputStream bufferedOut = null;
FileInputStream inputStream = null;
FileOutputStream outStream = null;
try{
input = new FileInputStream(sss+"i18n/Resources_zh_CN.properties");
File file = new File(sss+"i18n/Resources_zh_CN1.properties");
long fileLength = 0;
if(!file.exists()){
file.createNewFile();
}else{
fileLength = file.length();
}
out = new FileOutputStream(file);
java.util.Properties  properties = new java.util.Properties();
properties.load(input);
Enumeration<Object> keys = properties.keys();
ArrayList<String> lists = Collections.list(keys);
Collections.sort(lists);
Collections.reverse(lists);
Map<String,String> resources = new HashMap<String,String>();
String nbsp = "\r\n";
for(String tmp : lists){
String value = properties.getProperty(tmp);
resources.put(tmp, value);
out.write(tmp.getBytes());
out.write("=".getBytes());
out.write(value.getBytes("UTF-8"));
out.write(nbsp.getBytes());
}
File newFile = new File(sss+"/i18n/new.jpg");
File outFile = new File(sss+"/i18n/Resources_zh_CN12.txt");
bufferedInput = new BufferedInputStream(new FileInputStream(newFile));
bufferedOut = new BufferedOutputStream(new FileOutputStream(outFile));
byte[] bytes = new byte[1024];

ByteArrayOutputStream  reader= new ByteArrayOutputStream ();
BufferedImage bi = ImageIO.read(newFile);
ImageIO.write(bi, "jpg", reader);
byte [] bytes1 =reader.toByteArray();
ByteArrayInputStream writer = new ByteArrayInputStream(bytes1);
BufferedImage biw = ImageIO.read(writer);
ImageIO.write(biw, "jpg", new File(sss+"/i18n/new3.jpg"));
while(bufferedInput.read(bytes) != -1){
bufferedOut.write(bytes);
}
inputStream = new FileInputStream(newFile);
outStream = new FileOutputStream(outFile);
FileChannel fileChannel = inputStream.getChannel();
FileChannel fileOutChannel = outStream.getChannel();
ByteBuffer buf = ByteBuffer.allocate(46);
int byt = fileChannel.read(buf);
while(byt != -1){
fileOutChannel.write(buf);
buf.flip();
byt = fileChannel.read(buf );
}
buf.clear();
fileOutChannel.close();


}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}finally{
if(bufferedInput != null){
try{
bufferedInput.close();
}
catch(IOException e){
e.printStackTrace();
}
}

if(bufferedOut != null){
try{
bufferedOut.close();
}
catch(IOException e){
e.printStackTrace();
}
}
if(input != null){
try{
input.close();
}
catch(IOException e){
e.printStackTrace();
}
}
if(out != null){
try{
out.close();
}
catch(IOException e){
e.printStackTrace();
}
}
if(inputStream != null){
try{
inputStream.close();
}
catch(IOException e){
e.printStackTrace();
}
}
if( outStream != null){
try{
outStream.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}
}
0 0
原创粉丝点击