Tag: 解析

有关Java上无效XML字符的错误

在Java上解析xml文件我得到错误: An invalid XML character (Unicode: 0x0) was found in the element content of the document. xml来自web服务。 问题是我只在webservice在localhost(windows + tomcat)上运行时才会收到错误,但是当webservice在线时(linux + tomcat)则不会。 我怎样才能替换无效的char? 谢谢。

快速CSV解析

我有一个java服务器应用程序,下载CSV文件并解析它。 解析可能需要5到45分钟,并且每小时发生一次。这种方法是应用程序的瓶颈,因此它不是过早优化。 到目前为止的代码: client.executeMethod(method); InputStream in = method.getResponseBodyAsStream(); // this is http stream String line; String[] record; reader = new BufferedReader(new InputStreamReader(in), 65536); try { // read the header line line = reader.readLine(); // some code while ((line = reader.readLine()) != null) { // more code line = line.replaceAll(“\”\””, “\”NULL\””); // Now remove all of […]

将字符串解析为URL

如何解析动态字符串值以创建URL实例? 我需要用%20 ,重音符号,非ASCII字符替换空格……? 我试图使用URLEncoder但它也编码/字符,如果我将一个用URLEncoder编码的字符串给URL构造函数,我得到一个MalformedURLException (没有协议)。

Java Email message Parser?

是否有人熟悉Java库,可以帮助解析下面的电子邮件的字段(日期,主题,从,到)? Message-ID: Date: Wed, 6 Mar 2010 12:32:20 -0800 (PST) From: someone@someotherplace.com To: someone@someplace.com Subject: some subject Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-From: one, some X-To: one X-cc: X-bcc: X-Folder: Bob\Inbox X-Origin: Bob-R X-FileName: rbob (Non-Privileged).pst some message

以(yyyy-MM-dd)格式解析字符串日期

我有“2013-09-18”forms的字符串。 我想将它转换为java.util.Date。 我这样做 SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”); Date convertedCurrentDate = sdf.parse(currentDateText); convertedCurrentDate将于’Wed Sep 18 00:00:00 IST 2013′ 我希望我的输出格式为’2013-09-18′ 小时,分钟和秒不应该来,它应该是yyyy-MM-dd的forms。

解析JSON文件Java

我想在java中解析一个JSON文件,并从下面提到的文件中获取以下值: { “status”: “OK”, “origin_addresses”: [ “Vancouver, BC, Canada”, “Seattle, État de Washington, États-Unis” ], “destination_addresses”: [ “San Francisco, Californie, États-Unis”, “Victoria, BC, Canada” ], “rows”: [ { “elements”: [ { “status”: “OK”, “duration”: { “value”: 340110, “text”: “3 jours 22 heures” }, “distance”: { “value”: 1734542, “text”: “1 735 km” } }, { “status”: […]

绑定不能解决eclipse中的AST处理问题

我正在使用eclipse JDT AST解析器来处理一些Java代码,并试图提取字段和方法声明的类型绑定。 这样做的逻辑在我的Visitor类中(见下文)。 不幸的是,我没有任何运气,也没有任何绑定解析(它们始终为空)。 有趣的是,绑定确实与eclipse ASTView插件在相同的代码上工作。 我究竟做错了什么? 这里有一些相关的代码片段,希望能帮助有人弄清楚发生了什么! ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(source); parser.setResolveBindings(true); CompilationUnit unit = (CompilationUnit) parser.createAST(null); GenericVisitor visitor = new GenericVisitor(outDir + “//” + file.getName() + “.xml”); visitor.process(unit); public class GenericVisitor extends ASTVisitor { public void endVisit(FieldDeclaration node) { String bindingInfo = “”; ITypeBinding binding = node.getType().resolveBinding(); if(binding == null) […]

java的自然语言日期和时间解析器

我正在研究一个自然语言解析器,它用英语检查一个句子,并提取一些信息,如姓名,日期等。 例如:“ 让我们下周二下午5点在海滩见面。 ” 所以输出将是这样的:“ 让我们在海滩的1700小时见到2009年9月15日 ” 基本上,我想知道的是, JAVA是否有任何框架或库可用于执行这些操作,例如从句子中解析日期并提供具有某种指定格式的输出。 此致,Pranav 谢谢你的回复。 我看过几个像LingPipe ,OpenPL, Stanford NLP这样的NLP 。 我想问他们为java的日期解析做了什么。

Integer.parseInt(string)实际上是如何工作的?

最近被问到这个问题并且不知道答案。 从高层可以解释Java如何获取字符/字符串并将其转换为int。 非常感谢 卡尔 编辑:也很高兴知道其他语言是否也做类似的事情。

如何在java中读取或解析MHTML(.mht)文件

我需要挖掘大多数已知文档文件的内容 ,例如: PDF格式 HTML doc / docx等 对于我计划使用的大多数这些文件格式: http://tika.apache.org/ 但截至目前, Tika不支持MHTML(* .mht)文件..( http://en.wikipedia.org/wiki/MHTML )C#中的例子很少( http://www.codeproject.com/KB /files/MhtBuilder.aspx )但我在Java中找不到。 我尝试在7Zip中打开* .mht文件但它失败了……虽然WinZip能够将文件解压缩为图像和文本(CSS,HTML,Script)作为文本和二进制文件… 根据MSDN页面( http://msdn.microsoft.com/en-us/library/aa767785%28VS.85%29.aspx#compress_content )和前面提到的code project页面…… mht文件使用GZip压缩。 … 尝试在java中解压缩导致以下exception:使用java.uti.zip.GZIPInputStream java.io.IOException: Not in GZIP format at java.util.zip.GZIPInputStream.readHeader(Unknown Source) at java.util.zip.GZIPInputStream.(Unknown Source) at java.util.zip.GZIPInputStream.(Unknown Source) at GZipTest.main(GZipTest.java:16) 并使用java.util.zip.ZipFile java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.(Unknown Source) […]