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();
}
}
}
}
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
- Java流的操作使用
- 使用java 操作MongoDB 的增删操作
- Java IO操作——合并流SequenceInputStream的使用
- java-流的操作
- java流的操作
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- 使用java操作oracle的blob字段
- 使用Java操作文本文件的方法详解
- 使用Java操作XML的实例
- 使用Java操作文本文件的方法详解
- 使用Java操作文本文件的方法详解
- java操作Excel及HSSFWorkbook的使用
- 使用Java操作文本文件的方法详解
- http协议二
- 什么才算是真正的编程能力?
- gnuplot画图二
- 欢迎使用CSDN-markdown编辑器
- Lucene 4.X 倒排索引原理与实现: (3) Term Dictionary和Index文件 (FST详细解析)
- Java流的操作使用
- 机器学习基础(一)——如何避免浮点数下溢
- Location Services and Maps Programming Guide 纪录
- java中currentTimeMillis()和Math.random()
- 正则表达式学习笔记
- hadoop-2.7.2+hive 2.0.0采用LZO压缩的坑好深
- 莫比乌斯反演升级版 HDU 4746
- 解决mysql中文显示为问号
- 在iOS开发中为什么使用多线程以及多线程的使用