简体   繁体   English

使用JAVA解析逗号分隔文件

[英]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.

相关问题 用Java将逗号分隔的文件读入多维数组 - Reading comma delimited file into a multidimensional array in Java Java - 将管道和逗号分隔的文件转换为 xml - Java - convert pipe and comma delimited file into xml 使用简单的json解析设备数据并在hdfs中构建逗号分隔文件 - Parse device data with simple json and building a comma delimited file in hdfs Java - 解析分隔文件并查找列数据类型 - Java - Parse delimited file and find column datatypes 在java中使用regex从列分隔文件中的字段内的货币字段中删除美元符号和逗号 - Using regex in java to remove a dollar sign and comma from a currency field within a field in a column delimited file 如何在Apache Poi中使用Java以CSV逗号分隔格式编写Excel文件? - How to write excel file in csv comma delimited format using java in Apache poi? 如何使用Java / jsp中的split()读取逗号分隔的文本文件以分隔每个元素 - How to use read a comma delimited text file using split() in java/jsp to seperate each element 尝试解析以(,)分隔并使用引号的CSV文件 - Trying to parse a CSV file, delimited by ( , ) and using quotes 使用CSVParser解析制表符分隔的文件 - Using CSVParser to parse a tab-delimited file 使用 split 解析分隔的文本文件 - parse delimited text file using split
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM