[英]Parse a Comma Delimited File using JAVA
I want to read this file:- 我想阅读这个文件:
http://www.somehost.com/products/, A0,D1,L0,T0
http://www.somehost.com/news/rel, A1,D0,L1,T0
http://istor.somehost.com, A0, D1, L0, T0
I have a list of urls and I want to compare those url's with the url's that are there in this file. 我有一个网址列表,我想将这些网址与该文件中的网址进行比较。 And Suppose the url that I wanted to compare starts with the url that is there in these file.. Then it will move forward in that url line and it will check for A and D. If A is 0 then we will not crawl that url and vice versa and If A is 1 then we will move forward and see whether L is 0 or 1 means if L is 1 then we will extract link only and vice versa and same with T is 0 or 1, we will extract text only if T is 0.
并假设我要比较的网址以这些文件中的网址开头。然后它将在该网址行中前进,并将检查A和D。如果A为0,那么我们将不抓取该网址反之亦然,如果A为1,那么我们将向前看L是否为0或1意味着L为1,那么我们将仅提取链接,反之亦然,与T相同的是0或1,则仅当以下情况提取文本: T是0
Any suggestion how can I do this.. ?? 任何建议,我该怎么办.. ??
I've used Java CSV and it's pretty easy. 我使用过Java CSV ,这非常简单。 See the code examples as well.
也请参见代码示例 。 However (summarizing what @Hovercraft Full Of Eels said), if your data are not overly complicated, Java's String.split() should work fine.
但是(总结@Hovercraft Full Of Eels所说的话),如果您的数据不是太复杂, Java的String.split()应该可以正常工作。
After parsing your data you can, you know, read the values and determine what to do from there. 解析数据后,您可以知道读取值并从中确定要做什么。 Your description of what you need to do is practically an outline of a method with an
if ... else if ... else
structure, so start from that. 您对您需要执行的操作的描述实际上是具有
if ... else if ... else
结构的方法的概述,因此从此开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.