简体   繁体   中英

c# - Create and upload csv file to ADLS

I am trying to create a.csv file to upload into ADLS using DataLakeFileClient and MemoryStream . It works fine but the csv file has a garbage value after each letter in the csv. (I can see those as 'NUL's when I download and open the file in notepad++).

Here is my code:

 DataLakeFileClient fileClient = new DataLakeFileClient(new Uri($"https://{accountName}.dfs.core.windows.net/{container}/{directory}/{filename}"), credential); UnicodeEncoding uniEncoding = new UnicodeEncoding(); using (MemoryStream memStream = new MemoryStream(100)) { byte[] colString = uniEncoding.GetBytes("a,b,c,d,e,f"); memStream.Write(colString, 0, colString.Length); memStream.WriteByte(0x0A); byte[] dataString = uniEncoding.GetBytes(string.Join(",", "val1","val2","val3","val4","val5","val6")); memStream.Write(dataString, 0, dataString.Length); memStream.Position = 0; fileClient.Upload(memStream); }

It's because your LF (0x0A) is one byte instead of 2. Add after it another byte:

memStream.WriteByte(0x0A);
memStream.WriteByte(0x0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM