This article introduces java File Read and Write instances, including saving remote files to this address and reading and writing csv files. If you are interested, refer.
File file = new File
problem occurs in the judgment condition of the while loop. Ready () is the decision to stop the input stream and not necessarily the end of the file. The conclusion of the file should be the following statement:
The code is as follows
Copy Code
(line = Br.readline ())!= null
So that you can finish reading the original file
# 1.34BUnited States # Washington D.C. # 0.31B
3. Use other separator numbers and skip some rows. For more information, see here: Click to open the link.
CSVReader reader = new CSVReader (new FileReader (file ),';')CSVReader reader = new CSVReader (new FileReader (file ),'#')
Skip the first five rows, starting from the first 6th rows:
CSVReader reader = new CSVReader(new FileReader(
Java opencsv-use Spring's PostConstruct mechanism to read the CSV configuration file to the memory map at project startup
A. studentconfig.csv file:
ID, NAME, SCORE1, Zhang San, 1002, Li Si, 903, Zhao Wu, 604, Wang Liu, 55
Ii. StudentConfigBean.
Recently used to read the CSV file, the following is the source, read the CSV file, converted to a string type of the list object, which was processed at noon, otherwise garbled, FilePath is the path of the
Tag: coded head close resolves ACS har write DMI ImportFirst, be prepared to download a Javacsv.jar rack packagepublic void Readecsv () {try { ArrayListString cell = csvlist.get (row) [0]; You can specify the fetch content by obtaining the data in column No. 0 of Row row System.out.println("姓名:"+cell) } }catch(Exception ex){ System.out.println(ex); } }/**
Writing to a
=[] $ - #循环数组 - forListinchlists: the - #获取每一行数据 and use a comma to unpack the user name and passwordWuyi#list ="grace,1" the#list. Split (",") =[grace1,1] #csv是用逗号分隔, the following list.split (",")[0] is the 1th element in the Grace1,list.split (",")[1the 2nd element in the] is 1 -Username=list.split (",")[0].strip () WuPwd= List.split (",")[1].strip () - About print (userName) $ print (PWD) - - #开始浏览登陆 -Driver =Webdriver. Firefox () ADriver
The first paragraph is read file, download.
The second paragraph is a string download.
Copy the Code code as follows:
$fileName = "Prefs.csv";Header (' Content-type:application/octet-stream ');Header (' content-disposition:attachment; Filename= '. $fileName);Header (' content-transfer-encoding:binary ');Header (' Content-length: '. FileSize ($fileName));ReadFile ($fileName);
Copy the Code code as follow
Download the CSV file in PHP code, can be a string, or a CSV file, the following directly on the codeThe first paragraph is read file, download. The second paragraph is a string download. The code is as follows: csv"; Head
This note will be the operation of the previous note to make some improvements, no longer the HTM file in the Saz file parsing out, but not to read the data directly into the string, the basic idea is as follows:1. Customize a class that reads content from a text file to a string: Parses an HTM document in a saz
/** * Read Parse CSV file, will read the result output of the console, and encapsulated into 4 teacher objects. * 1, Clay Turtle, 13101015338, Haidian District 2, Mimi, 13201015338, Chaoyang District, Beijing 3, Kokura, 13601015818, Beijing Xuanwu District 4, Rice Island Love, 13201025818, Chaoyang District, Beijing/**
To read a CSV file in this way:
All the data is taken out at once, the first line of the file is the title, the second row is to take the data, how to take?
Also read the non-English characters displayed as garbled, how to deal with it?
Reply content:
To
contains a comma character, which must be enclosed in double quotation marks. (The 6 ) field contains a newline character, which must be enclosed in double quotation marks. (7 ) contains spaces before and after the field, which must be enclosed in double quotation marks. (a b C ==> "a b C" ) (8 ) The double quotation marks in the field, expressed in two double quotation marks. (I said: "abc" .) ==> I said: abc. ) (9 ) if there are double quotes in the field, the field must be enclosed in
generic encoding.In short, the comma is separated by a double quotation mark is the value of the data format does not have a very uniform standard but in order to avoid the error we developed the uniform format is this"Name", "pwd", "date""Zhang San", "123", "2015-09-30"And then the default format for code processing is that it's actually the form of plain text.Why use a CSV fileThis involves data interoperability issues, some programs support the ta
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.