file-io

Unable to properly read the lines from a file

给你一囗甜甜゛ 提交于 2020-07-22 06:12:10
问题 I have file, which i wrote using a python script . The file is large and contain more than a 1000 lines, and each line is very large and it goes like :(shortened) 1 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1

Printing number of lines in a file without using fgets

拥有回忆 提交于 2020-07-10 07:17:27
问题 So I am trying to print the number of lines in a file. The catch is that I cannot use fgets. Is there any other alternative to this which involves only fscanf? I tried running the following: while (1) { ret = fscanf(fin, "%[^\n]", string); if (ret == EOF) break; line_count++; } But it does not work. It is giving me an infinite loop. Can anyone please tell me what the issue is ? 回答1: this statement: ret = fscanf(fin, "%[^\n]", string); should be: ret = fscanf(fin, " %[^\n]", string); Notice

Reading millions of small files with C#

半世苍凉 提交于 2020-07-09 08:54:56
问题 I have millions of log files which generating every day and I need to read all of them and put together as a single file to do some process on it in other app. I'm looking for the fastest way to do this. Currently I'm using Threads, Tasks and parallel like this: Parallel.For(0, files.Length, new ParallelOptions { MaxDegreeOfParallelism = 100 }, i => { ReadFiles(files[i]); }); void ReadFiles(string file) { try { var txt = File.ReadAllText(file); filesTxt.Add(tmp); } catch { } GlobalCls

Write to file in uwp that has been drag-dropped from explorer

旧街凉风 提交于 2020-07-09 05:55:24
问题 If file is dragged and dropped from file explorer it has FileAttributes.ReadOnly flag for StorageFile.Attributes parameter. In that case using StorageFile api to write to file will give error. How to write to file in this case?? 回答1: In this case PathIO api can be used to write to file (unless file is a system file). Convert data to write into bytes array and then add following code to write to file: await PathIO.WriteBytesAsync(file.Path, bytes); This will write to these files without any

Uploading large files to Controller in chunks using HttpClient, IFormFile always empty

帅比萌擦擦* 提交于 2020-07-09 05:26:44
问题 I am trying to create a .Net Standard "Client" class for uploading (sometimes very large) files to a Controller. I want to do this by breaking the file into chunks and uploading them one at a time. The intent is for other applications to use this instead of communicating directly to the Web Api. I already have the Controller working. I've verified that it works using a Kendo-ui control which supports chunk-saving. The issue I am having is that the IEnumerable<IFormFile> files parameter for my

Uploading large files to Controller in chunks using HttpClient, IFormFile always empty

柔情痞子 提交于 2020-07-09 05:26:12
问题 I am trying to create a .Net Standard "Client" class for uploading (sometimes very large) files to a Controller. I want to do this by breaking the file into chunks and uploading them one at a time. The intent is for other applications to use this instead of communicating directly to the Web Api. I already have the Controller working. I've verified that it works using a Kendo-ui control which supports chunk-saving. The issue I am having is that the IEnumerable<IFormFile> files parameter for my

Creating a file with open() or creat() has fewer permission bits set than I asked for

随声附和 提交于 2020-07-03 10:01:26
问题 I am writing a program to mimic the cp utility. However, I cannot get the file permissions to work correctly. I know that they are stored in the structure stat and stored in the st_mode field with stat . My issue is that I do not get the write permission for the group or other categories, i.e. I get -rwxr-xr-x as the permissions for the file even though the source file is -rwxrwxrwx . The statement where I set the permissions is below. if ( (dest_fd = open(dest_file, O_WRONLY|O_CREAT, (stats

Getting the cluster size of a hard drive (through code)

限于喜欢 提交于 2020-06-27 07:04:18
问题 I need to find the cluster size of the users hard drive, through C or C++. The hard drive uses NTFS (though I'd appreciate knowing how it's done on other file systems as well). I guess what I need is some combination of win32 API calls, but I don't know which. For instance, typing "fsutil fsinfo ntfsinfo c:" in the windows console gives you "Bytes per cluster", which is what I need. (Though for obvious reasons, I don't want to run that command and parse it's output.) 回答1: Use the

The first character is cut off when BufferedReader is used

时间秒杀一切 提交于 2020-06-25 10:14:20
问题 This is the code : File file = new File("Hello.txt"); file.createNewFile(); FileWriter write = new FileWriter(file); BufferedWriter bufWrite = new BufferedWriter(write); bufWrite.write("HelloWorld"); bufWrite.flush(); bufWrite.close(); FileReader read = new FileReader(file); BufferedReader bufRead = new BufferedReader(read); while(bufRead.read()!=-1){ System.out.println(bufRead.readLine()); } bufRead.close(); Here, the output is elloWorld. 'H'is not there. Why is it so? Not sure if I'm doing

The first character is cut off when BufferedReader is used

有些话、适合烂在心里 提交于 2020-06-25 10:14:17
问题 This is the code : File file = new File("Hello.txt"); file.createNewFile(); FileWriter write = new FileWriter(file); BufferedWriter bufWrite = new BufferedWriter(write); bufWrite.write("HelloWorld"); bufWrite.flush(); bufWrite.close(); FileReader read = new FileReader(file); BufferedReader bufRead = new BufferedReader(read); while(bufRead.read()!=-1){ System.out.println(bufRead.readLine()); } bufRead.close(); Here, the output is elloWorld. 'H'is not there. Why is it so? Not sure if I'm doing