Questions tagged [file-handling]

file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files

2915 questions
3
votes
1 answer

Can you tie() a filehandle without a bareword glob?

I'm trying to use Device::SerialPort without a bareword glob, see questions at the bottom. Here is their example: $PortObj = tie (*FH, 'Device::SerialPort', $Configuration_File_Name) print FH "text"; ... but polluting the namespace with *FH feels…
KJ7LNW
  • 1,437
  • 5
  • 11
3
votes
1 answer

Error in fromJSON("employee.json") : not all data was parsed (0 chars were parsed out of a total of 13 chars)

I was trying to read the JSON file from my r studio as a purpose of learning how to read JSON file, but suddenly i got an parsing error. employee.json { "id" : ["1","2","3","4","5","6","7","8" ], "name" :…
Gourav
  • 47
  • 1
  • 8
3
votes
4 answers

How can I find and replace text in a larger file (150MB-250MB) with regular expressions in C#?

I am working with files that range between 150MB and 250MB, and I need to append a form feed (/f) character to each match found in a match collection. Currently, my regular expression for each match is this: Regex myreg = new Regex("ABC:…
nightmare637
  • 635
  • 5
  • 19
3
votes
1 answer

Does std::ofstream guarantee the old open file will be closed if opening new one?

#include int main() { auto fout = std::ofstream("/tmp/a.txt"); fout.open("/tmp/b.txt"); // Will "/tmp/a.txt" be closed? fout.open("/tmp/c.txt"); // Will "/tmp/b.txt" be closed? } Does std::ofstream guarantee the old open file…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
3
votes
2 answers

expected declaration specifiers or ‘...’ before ‘FILE’

I am writing code in c. I am declaring a FILE* fp at the main function (main.c). We have other files at the project too. So at a header file I am getting this error: "expected declaration specifiers or ‘...’ before ‘FILE’ problem" at this line: void…
ChrisAsl
3
votes
1 answer

How to write logging messages to a file

I am trying to use the Python logging library. Instead of printing the messages in the console, I want to write them to a file. Based on the documentation , I'm a little unsure of how to do this. First I imported the logging in and then I created my…
gwydion93
  • 1,681
  • 3
  • 28
  • 59
3
votes
1 answer

Load and save a large amount of structured data to and from a file c++

I have a system that has lots of Blocks of data stored in a vector of structs The struct looks like this: class Block { public: Blockheader header; uint32_t index; std::string hash; std::string prevhash; std::vector
Ariel Hurdle
  • 68
  • 1
  • 13
3
votes
3 answers

Changing File's last modified without closing it

File's last modified time is changed only when the file is closed. public class Main { public static void main(String[] args) throws IOException { File f = new File("xyz.txt"); FileWriter fwr = new FileWriter(f); …
raj
  • 3,769
  • 4
  • 25
  • 43
3
votes
1 answer

How to create a directory on statup in spring boot project

I am making a directory to store all uploaded files in my spring boot app on startup. The path of this directory is stored in application.properties file. I am trying to read this path and create a directory on startupof project. I am not able to…
omkar
  • 55
  • 1
  • 6
3
votes
1 answer

JSON.parse error while writing json data into json file

I am trying to get JSON data from a localhost URL row by row and insert it into a JSON file. When I try to open the file, I receive an error that says Multiple JSON root elements. import urllib.parse import urllib.request, json import…
Devang Hingu
  • 578
  • 1
  • 6
  • 20
3
votes
8 answers

Speed Tradeoff: Frequently Reading from file vs storing it using dynamic memory

I am writing a C program which involves reading a image file and reading each pixel of image just once. So should i read file once using fread() and store it in some dynamic variable(heap variable) or frequeently use fread() for each pixel?? Image…
singhsumit
  • 964
  • 1
  • 9
  • 26
3
votes
3 answers

how to read file and print in reverse order using stack C++

I have to read text file each word at a time and then push that word to stack and then pop each word at a time to print in the display. I have tried the following code but after running the program, compiler just shows the blank screen with no…
muzzi
  • 372
  • 2
  • 13
3
votes
2 answers

Error in free(): invalid size

#include using namespace std; class student { string name; string reg; public: void getdata() { getline(cin,name); getline(cin,reg); } void printdata() { cout<
ankit
  • 324
  • 1
  • 4
  • 11
3
votes
2 answers

Does BufferedWriter's write(String S) method actually buffer?

As per the Java SE 8 Documentation, the BufferedWriter class has the following methods of its own(w.r.t writing data): write(char[] cbuf, int off, int len) write(int c) write(String s, int off, int len) As I confirmed from checking the source code…
Nilashish C
  • 375
  • 2
  • 11
3
votes
1 answer

Copying from one directory in HDFS to another directory in HDFS using JAVA

I am trying to copy the data from one directory in HDFS to another directory in HDFS but I am facing few issues. This is my code snippet. Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); …
Deepak
  • 103
  • 1
  • 9