We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [file]

A block of arbitrary information, or resource for storing information, accessible by the string-based name or path. Files are available to computer programs and are usually based on some kind of persistent storage.

Filter by
Sorted by
Tagged with
9
votes
2answers
4k views

Proper way of handling exceptions while reading user input from file

I am parsing a text file (UTF-8) and checking for several conditions that need to be satisfied for the code to be happy. If not, then there is no point to continue and the program should die. At the ...
9
votes
2answers
1k views

Frequency count of single words and word pairs over 20 million tweets

My application needs to read 20-million-line text files and count the word frequencies for one and two words. For example: A B A B SSS G D A One word Frequency A: 3 B: 2 SSS: 1 G: 1 Two Word ...
9
votes
1answer
2k views

Markov chains to generate text

This is my Python 3 code to generate text using a Markov chain. The chain first randomly selects a word from a text file. Out of all the occurrences of that word in the text file, the program finds ...
9
votes
5answers
7k views

Reading binary file of doubles

I'm trying to read doubles from a relatively small binary file. This currently reads a 100 KB file in about 6 milliseconds in my system. I would like to reduce that if possible. ...
9
votes
2answers
17k views

Guessing a file type based on its content

In a project I'm working on, I need a component that is able to make a best guess about file's type based on its contents (a Stream). It doesn't need to do a ...
9
votes
3answers
145 views

Archiving files into directories

This program moves files to a backup directory, archiving them by year of last modification. From a directory like : ...
9
votes
2answers
354 views

Command-line utility to capitalize long words in a file

I have been developing a capitalizer in Python. This is actually a script that an end user will type at their terminal/command prompt. I have made this script to: Taking the first argument as a file ...
9
votes
2answers
45k views

User input and reading contents of file

For full disclosure: this is an assignment for my programming class and I just want tips or advice on some of the code. Assignment details just for background information purposes: Write a program ...
9
votes
1answer
641 views

Reading a file without blocking the main thread

Background Info: Running Python 3.6 on Windows 10 I have a text file parsed like this: Ann Marie,Smith,ams@cia.com There can over 100+ names in the text file. ...
8
votes
4answers
11k views

Read from a file and pick a random line

I've been learning Java lately and had some great feedback from the previous threads (hangman and guess a number games). I was challenged by a user to try to get this code done, so I'm posting it here ...
8
votes
5answers
3k views

Memory-safe file-reading in C

I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with ...
8
votes
4answers
9k views

Creating a unique file name in C#

I find that I am often writing files where the names either: Need to be incremented (rather than overwriting a file that already exists in the directory with the same name) Need to be timestamped ...
8
votes
3answers
13k views

Writing a large file of numbers

Basically, I want to write a huge file of numbers. Each line in that file should contain one number. This program below is extremely slow (obviously) but it works. It writes one line after line and ...
8
votes
3answers
445 views

Exception handling and general check in Java

Are the catch statements ok or must I put in a println()? In general, is the code good-looking enough? ...
8
votes
6answers
8k views

Sorting a list of first names from a text file

I applied for a job as a C#/.NET Junior Developer, and had a test to do:: Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, ...
8
votes
2answers
6k views

Python code that compares two files byte by byte

I wrote a Python (2.7) script that compares a file byte by byte. filecmp was not suitable for the application because it compares metadata as well. How can I ...
8
votes
2answers
673 views

Counting five specific words in a file

I'm trying to improve my code and i want to know if this is the best way to write this Switch or if there are other methods. ...
8
votes
2answers
3k views

Text Analyzer - Properly implementing Java coding style

As a new Java learner I would like to improve my coding style. I wrote a program which gets as an input a file name, and asks for two file names for the output. The first output file includes all the ...
8
votes
3answers
3k views

File encryption with password

I would like to have my C# cryptography code reviewed. I programmed an application that encrypts files with a password (provided by the user). It basically functions as a password manager, on the ...
8
votes
3answers
752 views

Find the greatest number in an array

The program reads a .txt file that contains lines of numbers. The first one has one number N and the second one has \$N\$ numbers as the first line says. The \$N\$ numbers is \$1 \le N \le 1.000.000\...
8
votes
3answers
3k views

Checking if file is within a directory for security

I have a security manager I'm writing for a Java program, and within the checkRead method, I wish to only allow reads to files within a given directory. The basis of it is that it will get a ...
8
votes
3answers
915 views

XOR cipher C program

I was learning about getopt to parse command line options and I decided to write this small XOR cipher program for files. It acts as a "UNIX filter" (I guess) ...
8
votes
2answers
2k views

Read matrix from file, the C++11/14 way

I am trying to get acquainted with C++11/14, so please tell me if the code below could be written in a more "modern" way. Or, of course, if it could be improved in any way. The function ...
8
votes
2answers
833 views

Q&A-based file editor

As part of my autodidacticism into all things Python related, I have decided to write a number of functions that I can save in a library for future use. One such function that struck me as useful to ...
8
votes
2answers
136 views

Usage of scanner

I have a legacy method which I would like to clean up: ...
8
votes
1answer
392 views

Non-curses pager in C

I have written a pager in C that is supposed to be used in systems where curses is not installed (or broken). It can also be used as a system-wide pager, it works ...
8
votes
2answers
1k views

Sorting a set of numbers in a file using Java BitSet

I have implemented a program to sort a file consisting of numbers. The program generates a different output file with all numbers sorted in it. I have implemented this program using ...
8
votes
2answers
195 views

Read file into vector<byte>

I need to read a range of bytes from a file and return it as a std::vector<std::byte>. My current code looks like this: ...
8
votes
2answers
8k views

C program to count number of lines in a file

Very simple code, works fine. I'm mainly interested in the method I used to count lines. I thought about using fgetc, but I'm not even sure if it'd read the newline character, and I think it's slower ...
8
votes
4answers
874 views

Python Implementation - Conway's Game of Life

This is my implementation of Conway's Game of Life in Python. Now since I am a novice coder, naturally I have some key doubts: The usage of idioms and code redundancies - Are there any small ...
8
votes
2answers
1k views

Reusable, generic save method

I am developing a Python script that will process large amounts of data from an experiment. Files are read in, calculations are made, images are plotted and saved as .pngs, and calculated parameters ...
8
votes
1answer
90 views

Implementing a File class

I studying for a Python course. I was finished working on task about creating a file class which can read, write lines to file. This class also needs magic methods (...
8
votes
1answer
152 views

Function to wrap words in a text editor without breaking them

These are 3 functions I created in C language to read in a text file, remove the carriage returns from it in order to display on the screen, and display the file on screen wrapped with the words of ...
8
votes
1answer
2k views

Duplicate files finder in C++

I've came across this question https://stackoverflow.com/questions/11760420/what-is-an-optimal-way-to-find-duplicate-files-in-c and there are two answers for it both the answers convey that it is bit ...
8
votes
1answer
271 views

Extracting single files from a tarball (spreadsheets)

I've created a program that will pull spreadsheets out of a large tarball. First it specifies the file name through the "folio" number which is given as an argument when the program is called. From ...
7
votes
4answers
1k views

Merging two files containing sorted numbers into one

The task is to merge 2 text files containing sorted integers into one file. Each number in both files is stored in new line(there are no empty lines,and only numbers are stored). Requirements are that ...
7
votes
4answers
511 views

iTunes playlist copier

When you own an Android device and want your iTunes playlist to be copied over onto it, what do you do? What if your playlist hits something in the region of 20GB+ ? Well, I am sure I could've paid ...
7
votes
3answers
272 views

Convert binary raster file to text CSV

I have a binary file input.hgt from the Shuttle Radar Topography Mission. It contains a 3601✕3601 matrix, stored as 2-Byte big-endian integer numbers. My code ...
7
votes
2answers
2k views

Project Euler #22 - Name scores

I have written code in C++ 11 and check output with Project Euler site, and it is correct. I am not showing output, just to keep it secret, at least from my end. Please review my C++ 11 code. ...
7
votes
4answers
24k views

Getting the length of a file in characters

Here's my function for getting the length of a file, in characters: ...
7
votes
2answers
1k views

Find and rename all png files

I have such problem : find all png files to disk and rename them as I did: ...
7
votes
4answers
9k views

Reversing the lines of a file

I am trying to reverse the lines of a file by reading the file through an array. Is there a more efficient and quicker way of achieving this? ...
7
votes
3answers
11k views

Append a string to each line in a file

I wrote (several months ago) a program that will take an input file, with a provided std::string, and append that to each individual line in the file. Looking at ...
7
votes
2answers
139 views

Finding phrase in specified files

Please provide constructive feedback so I can learn from my mistakes. Please tell me what I did right and where I came up with very good solution and where I should improve. Here is the code (Please ...
7
votes
2answers
2k views

Read file into char*

Because I use the task so often, I wrote a C header for reading a file. I never formally learned C, so I'd really appreciate a code review on the code. As a matter of personal taste, I do not put a ...
7
votes
4answers
43k views

Count occurrence of words in a .txt file

I'm taking an intro to programming class and although I've learned some things I didn't know before (I've been using Python for about 1.5 years) I feel like I've not progressed much in writing "...
7
votes
3answers
470 views

Validating lines in a file using certain specifications

I have written a program which basically reads a file named "data.txt" line-by-line. As a line is read, it validates the line with a certain specification. If the specification is met, it will ...
7
votes
3answers
803 views

Invert rows and columns in an Excel file

Annother little excercise with openpyxl: Say you have a Excel file like this: The Goal is to make make it look like this: My code to acomplish this: inversion.py ...
7
votes
1answer
17k views

Splitting a CSV file with headers

I have been looking for an algorithm for splitting a file into smaller pieces, which satisfy the following requirements: The first line in the original file is a header, this header must be carried ...
7
votes
3answers
185 views

Console based Vocabulary Trainer

This code was reworked and repostet in Console based Vocabulary Trainer Version 2 I wrote a console based Vocabulary Trainer to practice C++. Its possible to add and remove vocabulary and practice ...