- 浏览: 106677 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
u013246812:
谢谢博主帮我解决了问题,就是那个process.exitVal ...
Java执行Shell脚本超时控制 -
fireinjava:
fireinjava 写道配置好多哦 =.=
刚看了下,原来是 ...
Java Spring2.5 Remote Invoke HTTP Invoker -
fireinjava:
配置好多哦 =.=
Java Spring2.5 Remote Invoke HTTP Invoker -
lee79:
呵呵,讲的很对
Java执行Shell脚本超时控制 -
fangwei:
非常感谢!!!btw 你虽然用到了slf4j,却没有用到它的强 ...
Java执行Shell脚本超时控制
在Java应用开发中,经常会遇到不同的开发人员的IDE设置的文件编码格式不一样,在后续集成环境中往往会因为file encoding不同引发一些小问题,故编写了一个小程序做文件转换动作。
import java.io.*; public class FileEncodingConverter { //Java file extention public static final String FILE_EXTENTION_JAVA = ".java"; public static final int BUFFER_SIZE = 1024 * 4; //File encoding public static final String FILE_ENCODING_UTF8 = "UTF_8"; public static final String FILE_ENCODING_GBK = "GBK"; public static final String FILE_ENCODING_GB2312 = "gb2312"; /** * File filter, only directory and java file */ private static FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { //directory and java file return file.isDirectory() || (file.isFile() && file.getName().endsWith(FILE_EXTENTION_JAVA)); } }; /** * @param sourceDirectoryPath sourceDirectory * @param destDirectoryPath destDirectory * @param sourceFileEncoding sourceEncoding * @param destFileEncoding destEncoding */ public static void scanDirectory(String sourceDirectoryPath, String destDirectoryPath, String sourceFileEncoding, String destFileEncoding) { File destDirectory = new File(destDirectoryPath); if (!destDirectory.exists()) { destDirectory.mkdir(); } File sourceDirectory = new File(sourceDirectoryPath); scanDirectory(sourceDirectory, sourceDirectoryPath, destDirectoryPath, sourceFileEncoding, destFileEncoding); } /** * @param directory directory * @param sourceDirectoryPath sourceDirectory * @param destDirectoryPath destDirectory * @param sourceFileEncoding sourceEncoding * @param destFileEncoding destEncoding */ private static void scanDirectory(File directory, String sourceDirectoryPath, String destDirectoryPath, String sourceFileEncoding, String destFileEncoding) { File[] files = directory.listFiles(fileFilter); File destFile; for (File file : files) { if (file.isDirectory()) { destFile = new File(destDirectoryPath + file.getAbsolutePath().substring(sourceDirectoryPath.length())); if (!destFile.exists()) { destFile.mkdir(); } scanDirectory(file, sourceDirectoryPath, destDirectoryPath, sourceFileEncoding, destFileEncoding); } else { System.out.println("Source file:\t" + file.getAbsolutePath() + "\nDest file:\t" + (destDirectoryPath + file.getAbsolutePath().substring(sourceDirectoryPath.length())) + "\n-----------------------------------------------------------------"); convertFile(file.getAbsolutePath(), destDirectoryPath + file.getAbsolutePath().substring(sourceDirectoryPath.length()), sourceFileEncoding, destFileEncoding); } } } /** * @param sourceFilePath sourceFilePath * @param destFilePath destFilePath * @param sourceFileEncoding sourceFileEncoding * @param destFileEncoding destFileEncoding */ private static void convertFile(String sourceFilePath, String destFilePath, String sourceFileEncoding, String destFileEncoding) { InputStream in = System.in; OutputStream out = System.out; Reader reader = null; Writer writer = null; try { //set up byte streams if (sourceFilePath != null) { in = new FileInputStream(sourceFilePath); } if (destFilePath != null) { out = new FileOutputStream(destFilePath); } // Use default encoding if no encoding is specified. if (sourceFileEncoding == null) sourceFileEncoding = System.getProperty("file.encoding"); if (destFileEncoding == null) destFileEncoding = System.getProperty("file.encoding"); // Set up character stream reader = new BufferedReader(new InputStreamReader(in, sourceFileEncoding)); writer = new BufferedWriter(new OutputStreamWriter(out, destFileEncoding)); char[] buffer = new char[BUFFER_SIZE]; int len; while ((len = reader.read(buffer)) != -1) { writer.write(buffer, 0, len); } } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } try { in.close(); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { String sourceDirectoryPath = "D:\\Lee\\Products\\insquery\\src"; String destDirectoryPath = "D:\\Lee\\Products\\insquery\\dest"; scanDirectory(sourceDirectoryPath, destDirectoryPath, FILE_ENCODING_GBK, FILE_ENCODING_UTF8); } }
发表评论
-
Spring声明式事务管理与配置详解
2015-08-18 09:00 01、Spring声明式事务配置的五种方式 前段时间对 ... -
Log4j的配置与使用详解
2015-08-18 08:44 7811、介绍 Log4j是Apache的一个开放源代码项目 ... -
Web.xml
2015-08-18 08:35 450web.xml文件详解 前言:一般的 ... -
Spring Filter
2015-08-18 08:23 5211、简介 Filter也称 ... -
springSecurity源码分析——DelegatingFilterProxy类的作用
2014-12-16 13:56 709http://www.cnblogs.com/hzhu ... -
spring data jpa 中的OpenEntityManagerInViewFilter 取代OpenSessionInViewFilter
2014-12-05 13:52 0http://blog.csdn.net/lzwglory/ ... -
servlet tomcat web.xml配备信息说明
2014-12-05 13:50 0servlet tomcat web.xml配置信息说明 ... -
Spring IntrospectorCleanupListener
2014-12-05 12:40 667spring中提供了一个名为 org.springfr ... -
Spring IOC容器实例化Bean的方式与RequestContextListener应用
2014-12-05 12:35 1079spring IOC容器实例化Be ... -
SpringBean的5种作用域
2014-12-05 12:33 803org.springframework.web.contex ... -
Lobback日志文件
2014-12-05 12:29 1185Logback是由log4j创始人Ceki Gülcü设计的 ... -
HTML Element
2012-08-05 17:16 9671. select 1) Clear Select O ... -
Prototype Study (转)
2012-08-05 16:49 817什么是Prototype Prototype 是由 S ... -
Prototype Element
2012-08-05 16:46 9371. select <select name=&q ... -
IE Firefox 一些组件的特殊处理
2012-07-29 09:04 8841、html alt 在IE下控件的alt属性使用赋值后,当 ... -
log4j 自动生成 appender
2011-05-04 21:55 1679一般log4j的配置是通过log4j.properties或x ... -
Java ASP Post
2011-03-06 20:32 1196用Java编写的模拟ASP Post请求写的一个上海的违章查询 ... -
Java Spring2.5 Remote Invoke HTTP Invoker
2011-03-06 20:16 2700近日,一个项目涉及到 ... -
Java Spring1.2 Remote Invoke HTTP Invoker
2011-02-25 09:12 1334近日,一个项目涉及到系统间接口调用,考虑到系统间用的都是jav ... -
When Runtime.exec() won't
2009-07-02 12:31 1056As part of the Java language, t ...
相关推荐
【FileEncodingConverter文件编码转换工具】是一款高效实用的软件,主要功能是帮助用户解决不同文件在编码格式上遇到的问题。在计算机科学中,文件编码决定了文本文件中的字符如何被存储和解析,不同的编码方式(如...
public class FileEncodingConverter { public static void main(String[] args) { String sourceFilePath = "source.txt"; String targetFilePath = "target.txt"; String sourceEncoding = "GBK"; // 源文件...
1. **FileEncodingConverter**:这可能是一款专门用于文件编码转换的应用程序,它能帮助用户将一个文件或一组文件从一种编码格式(如UTF-8、GBK等)转换为另一种编码格式。这样的工具对于处理中文、日文、韩文等非...
public class FileEncodingConverter { public static void convertGBKtoUTF8(String sourceFilePath, String targetFilePath) throws IOException { FileInputStream fis = new FileInputStream(sourceFilePath);...
3. 使用第三方工具:还有一些专门的编码转换软件,如“File Encoding Converter”等,提供了图形化的用户界面,操作更加直观。 在进行编码转换时,要特别注意以下几个要点: 1. 转换前备份:始终在转换前备份原始...
在FileConverter中,开发者利用了System.Text命名空间下的类,如Encoding类,它可以识别并操作各种编码类型。编码识别通常通过分析文件头的字节序列来判断,例如,UTF-8文件的前三个字节是0xEF, 0xBB, 0xBF,而ASCII...
CodeDetectorDetect File encoding, Now support UTF-8,GBK,UTF-16LE,UTF-16BE, Java检查文件编码,主要针对中文文本。目前支持 UTF-8(BOM或无BOM)、GBK、UTF-16LE、UTF-16BE单个文件或文件夹,支持编码批量转换。...
很实用,pdf 转换到 Doc 可以保持 Pdf 原来的排版布局。 Convert PDF to Word, PowerPoint...Set the layout and text encoding of the output file and output image’s format, color, size, resolution and quality.
1. **安装插件**:首先,我们需要在Eclipse Marketplace中搜索并安装支持批量转换编码的插件,如“Encoding Manager”或“Character Encoding Converter”。这些插件能够帮助用户方便地更改工程中所有文件的编码格式...
converter.Document.Options.Web.DefaultEncoding = "UTF-8"; converter.AddPage(new PageSettings { Url = "http://example.com" }); var pdfData = converter.GeneratePdf(); File.WriteAllBytes("output.pdf...
4. 在右侧的“Text file encoding”下拉框中,选择“Other”,然后在弹出的列表中选择“UTF-8”。 5. 点击“Apply and Close”保存设置。 但是,这仅改变项目默认的编码设置,不会实际转换文件内容。为了实现文件...
The quality of the new image file can be manipulated, using options that affect the high contrast portions ('text', for DjVu images) and the background (the rest of the image) in different ways, ...
<project name="EncodingConverter" default="convert" basedir="."> <!-- 定义属性 --> <property name="encoding.from" value="GBK"/> <property name="encoding.to" value="UTF-8"/> <!-- 清理旧目标 -...
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/html4/strict.dtd"); transformer.setOutputProperty...
InputStreamReader reader = new InputStreamReader(new FileInputStream("file.txt"), "GBK"); ``` ##### 2. 设置JVM默认编码 通过修改JVM启动参数,可以改变默认字符集。这对于整个应用来说是一个全局设置。 ```...
ByteToCharConverter converter = ByteToCharConverter.getConverter(encoding); char c[] = converter.convertAll(b); for (int i = 0; i ; i++) { System.out.println(Integer.toHexString(c[i])); } // 字符到...
+ added converter from Rave Reports ConverterRR2FR.pas + added Cross.KeepRowsTogether property + optimised merging cells in the BIFF export + added property DataOnly to exports + pictures format in ...
with open(ENtextfile, 'w', encoding='utf-8') as en_file: en_file.write(pdf_text) if isTranslate: with open(CNtextfile, 'w', encoding='utf-8') as cn_file: for line in pdf_text.splitlines(): ...
Library for PC OverviewATRAC9™ Library for PC ReferenceATRAC9™ Seamless Playback TutorialATRAC9™ File FormatAudiodecCpu Library OverviewAudiodecCpu Library ReferenceAudiodec Library ...