FAQ Database Discussion Community


Skip a line using BufferedReader (skip, but not read it)

java,file,file-io,bufferedreader
Hi guys I am currently using BufferedReader to read files. I have something like: br.readLine() != null for each call loop. And now what should I do if I want to skip a line. Here, I've read several similar questions other people posted, most of them suggested using readLine(). I...

In C, append to file open for read by another program on Windows console and Linux

c,linux,file-io
I have two different C programs running on the same machine. The first program, called FileReader, opens a file for reading, and keeps it open. Periodically, I want another program, FileAppender, to open the file using the "a" (append) mode, append data, and then close the file. But I don't...

StreamWriter not appending to file, instead creating a new file in different directory

c#,file,text,file-io,streamwriter
I am attempting to write from one file to a temp file after making certain changes to some of the data in the source file. This was working until I extracted this logic into its own function. After running some tests I noticed that only the first line was being...

C++ basic fileIO locations

c++,osx,file-io
so I'm just starting to learn fileIO. I've been using a program called CodeRunner on my mac and I have a folder that contains: validsudoku.cpp, validsudoku, sudokugood0.txt The beginning of the code I wrote is: int main(int argc, char const *argv[]){ //string filetoopen; ifstream sudokutxtfile; string txtline; string sudokubox[9]; //bool...

Open,Close ObjectOuputStream but still want to Append the serialized objects tot the end ?

java,file-io
I am obliged to open a ObjectOutputStream, then write an object an finally close the stream. I do that multiple times using the following code : // try-with-statement is very practical try(FileOutputStream fos = new FileOutputStream("G.txt") ; ObjectOutputStream oos = new ObjectOutputStream(fos);){ oos.writeObject(v); } catch (IOException e) { e.printStackTrace(); }...

delete contents of nth file in a folder batch

batch-file,file-io,order
I have a program that does things with video files depending on the file order, so for example it calls on the 45th or 10th file in a folder, but never the same one twice. Now, to save SSD space I want to delete only the contents of that nth...

Reading binary file to a string but the types are mixed

c,file-io,syntax,binaryfiles
I'm trying to read a binary file but when I read its characters it doesn't looks like it's formatted with char type so for example the numbers don't have their ASCII value instead, their actual value but letters does have ASCII value. Why is that? Also, when I create a...

event driven pattern for writing chunks to a file - JS

javascript,design-patterns,file-io,webrtc,event-driven-design
I'm trying to transfer a file over WebRTC, and I'm struggling to figure out a good pattern for writing data as it's coming in. Since file chunks will be coming in at an unknown rate, I need to be able to write each chunk as it becomes available; this means...

File I/O in C - How to read from a file and then write to it?

c,file-io,fopen,fgetc
I'm new to file i/o in C, and in my code I want to read information from a text file and then write to it. I tried to open a csv file using fopen("file.csv", "r+t") in order to be able to read and then write to the same file. So...

Two XML files. Roughly same number of lines. One is twice the size of the other. How?

xml,vb.net,vba,file-io,filesize
I have been generating an XML sitemap using Access and VBA. I asked our developers to implement a server side solution so that it can be ran every night without me having to remember to do it. I generate the file by writing text to a file. Very simple. My...

Syncronize thread to wait for multiple threads

java,multithreading,file-io,synchronization
I have four threads makes processing on four files, then I want a thread to concatenate these files. My solution is to make a fifth thread (thread1) to concatenate. sum = new Thread() { public void run() { if (thread1.isAlive()) { synchronized (lock1) { while (thread1.isAlive()) { try { lock1.wait();...

implement class object and Arraylist

java,file-io,arraylist
I am new to Java and I have a task to do. I have created a class (Company) which looks like this public class Company implements Serializable { private String companyName; private String companyCode; private int shareNo; private double closingRate; /** * Initializes a newly created company object so that...

Read in 2D array

arrays,matlab,file,file-io
I'd like to read in the following format from a file into a 2D array: -1.2545186e-01 6.1235522e-01 -3.3039316e+00 -5.7215697e+00 -4.3039316e+00 -7.7215697e+00 Is there any (builtin-) function to it?...

How can I get the location of a user's Documents directory?

c#,file-io
I want to be able to write a string to a text file on any computer. For example string line = "Sample text to write" File.WriteAllText(@"C:\Users\Rolex James\Documents\sample.txt" , line); On another system this path would be different, is there a way of writing it such that you don't have to...

C++ and WinApi - usage of GetWindowText() to get parameters for C++ code

c++,winapi,file-io
I have coded some C++ console program which converts one filetype to another. I need to turn the console application into a window one. I have never made window applications. I have chosen WinApi, because I don't have much time and don't want to change IDE (DEV C++ 5.10), compiler/linker...

What is this C programming reading?

c,file-io,printf
This is the code I am trying to understand: #include <unistd.h> #include <fcntl.h> #include <stdio.h> int main(void){ unsigned long word; ssize_t nr; int file = open("koray.txt",O_RDONLY); nr = read(file,&word,sizeof(unsigned long)); printf("%li\n",word); } koray.txt has only 1 character that is k. When I run the program I see: [email protected]:~$ ./a.out 4195435...

Java - Running JAR refuses to load file in the same directory

java,file,file-io,properties
Quick one, gentlemen. I'm trying to deploy a program, which borks at the following code. I want to read a properties file named, adequately, properties. Properties props = new Properties(); InputStream is; // First try - loading from the current directory try { File f = new File("properties"); is =...

Is it safe to write to a descriptor after ENOSPC

c,unix,file-io
Imagine this situation: one process (A) continuously writes data to disk by creating large files, to which it appends data using separate write() commands another process (B), continuously deletes files from disk the assumption is that (B) deletes data fast enough that (A) has room to write. However, it is...

Display an updated average of random numbers in a file

c++,file-io,average
I have a program that displays one random number in file . #include <iostream> #include <fstream> #include <random> using namespace std; int main() { std::ofstream file("file.txt",std::ios_base::app); int var = rand() % 100 + 1; file<<var ; return 0; } Results after 4 trial : 1,2 2,20 3,40 1,88 I am...

Wrong string concatenation using strcat

c,arrays,string,file-io,fgets
I'm writing a program that reads strings from file, saves them to 'string buffer' and then concatenates those string and writes them to another file. #define _CRT_SECURE_NO_WARNINGS #include <cstdlib> #include <iostream> #include <string.h> #include <stdio.h> int main() { FILE *f = fopen("Read.txt", "r"); char line[20]; char buff[15][20]; int i =...

Writing in .txt without erasing the previous

java,file,file-io
I have notice in my code that, whenever I enter a new input, the previous text I entered is gone and completely being replace by the new one. How do I create a new one without removing the previous text? Here's is my code: String pangalan = nameField.getText().trim(); String edad...

How do I load data from a txt file into variables in my C program?

c,arrays,parsing,file-io,struct
I have a program that has a struct of channels: struct channel { char title[40]; float gain; float offset; }; int main (int argc, char **argv) { struct channel channels[8]; } And a text file called configurationSettings.txt that holds the information needed to fill up 8 channels: Title1 20 30...

python how to write list of lists to file

python,list,file-io
I am trying to write a list of lists of strings to a file. My big list is of the forme: 1.0 '0:25.0' '1:50.0' '2:131.0' '3:202.0' 1.0 '0:2.0' '1:36.0' '2:131.0' '3:188.0' -1.0 '0:56.0' '1:53.0' '2:55.0' '3:58.0' -1.0 '0:50.0' '1:51.0' '2:48.0' '3:55.0' and so on ... the first column is of...

Goto line number , and edit a string there in file using C++

c++,file,file-io
I am trying to make a function which gets two parameters one Line_number and 2nd a string. This function will open a File Pre-Populated and skip till Line "Line_number" is reached , get that line and post some other line instead.But it does not work. I have seen other solutions...

Getting integer data from txt file in Java

java,file-io,arraylist
I want to read a text file which has String and a few integers related to that string. This is the class that I have to write my program in: public List<Integer> Data(String name) throws IOException { return null; } I have to read the .txt file and find the...

How to handle the File hand-off from windows in a python program

python,windows,pdf,file-io
I want to set up my python program to process all pdfs that are opened on my system, and then hand the processed pdf off to a standard reader. So I register my program with windows as the default handler for .pdf files and windows presumably will run my program...

Cancel last line iteration on a file

python,python-3.x,for-loop,file-io
I need to iterate on a file, stop iteration on a condition and then continue parse the file at the same line with another function (That may change so I can't just add content in the previous function). An example file (file.txt) : 1 2 3 4 5 6 7...

I want to add a string in between of 2 strings in file, but in output whole text is getting appended at the end of file

python,file-io,append,python-2.6
Code : fo = open("backup.txt", "r") filedata = fo.read() with open("backup.txt", "ab") as file : file.write(filedata[filedata.index('happy'):] + " appending text " + filedata[:filedata.rindex('ending')]) with open("backup.txt", "r") as file : print "In meddival : \n",file.read() Expected Output : I noticed that every now and then I need to Google fopen all...

Is it bad to call write() on a file object frequently with small additions?

python,file,file-io,stress
I'm refactoring a horrendous python script that is part of the polycode project that generates lua bindings. I am considering writing lua lines out, as they are generated, in blocks. But my question in generic form is, What are the detriments/caveats of writing to a file very quickly? Take for...

Hadoop map reduce Extract specific columns from csv file in csv format

java,hadoop,file-io,mapreduce,bigdata
I am new to hadoop and working on a big data project where I have to clean and filter given csv file. like if given csv file has 200 columns then I need to select only 20 specific columns (so called data filtering) as a output for further operation. also...

How to close an OutputStream in the appropriate way?

java,file-io,client-server,fileinputstream,fileoutputstream
In my client server application, it is able to receive commands and give the results back. The problem occures when I try to download a file from server side. After entering the download command, the server prompt shows this error, java.net.SocketException: socket closed Image: Otherwise the programing is working fine,...

How to filter file paths then use the resulting paths

file,file-io,rust,filepath
I trying to get a list of mp3 from a directory. let dir_paths = fs::read_dir(&Path::new("some_directory")).unwrap(); let paths = dir_paths.filter(|x| match x.unwrap().path().extension() { None => true, Some(ext) => ext == "mp3" }); The Error Message src/main.rs:27:48: 27:49 error: cannot move out of borrowed content src/main.rs:27 let paths = dir_paths.filter(|ref x| match...

Error: Getting symbols in python output

python,python-2.7,text,file-io,editor
#I wrote the following code for making a text editor. print "This is a simple text editor" from sys import argv script, name = argv print "You have selected the file : %s" %name print "Opening the file...." t = open(name, 'r+') print "The contents of the file are" print...

XOR binary file in Ruby

ruby,file-io,binary
I'm trying to create a "xor" function in Ruby that takes in input a binary file and an hex value and generates a xored binary file in output. File.open("myfile.exe.xor",'w') do |f_xor| f_xor.puts File.open("myfile.exe", 'rb').to_i ^ 0xFF end This code seems not to return the correct xored file as the expected...

Linux: huge files vs huge number of files

linux,performance,amazon-web-services,file-io
I am writing software in C, on Linux running on AWS, that has to handle 240 terabytes of data, in 72 million files. The data will be spread across 24 or more nodes, so there will only be 10 terabytes on each node, and 3 million files per node. Because...

Why does command prompt show numbers before I begin?

c,file-io,printf,scanf
The command prompt shows numbers before program begins. Why? 2687688 is given but the numbers won't write to file? #include <stdio.h> #include <conio.h> int main(void){ FILE*nfPtr; int n; if ((nfPtr=fopen("c:\\Users\\raphaeljones\\Desktop\\newfile.dat","w"))==NULL) { printf ("Sorry! The file cannot be opened\n"); } else {//else 1 begin printf("Enter numbers to be stored in file\n");...

Binary Files in C++, changing the content of raw data on an audio file

c++,file,file-io
I have never worked with binary files before. I opened an .mp3 file using the mode ios::binary, read data from it, assigned 0 to each byte read and then rewrote them to another file opened in ios::binary mode. I opened the output file on a media player, it sounds corrupted...

NoSuchFileException when creating a file using nio

java,file-io,nio
I am trying to create a new file using java nio, and I'm running into a createFile error. Error looks like this: createFile error: java.nio.file.NoSuchFileException: /Users/jchang/result_apache_log_parser_2015/06/09_10:53:49 code segment looks like this: String filename = "/Users/jchang/result_apache_log_parser_" + filename_date; Path file = Paths.get(filename); try { Files.createFile(file); } catch (FileAlreadyExistsException x) { System.err.format("file...

I can't figure out why “cout” didn't work properly

c++,file-io
I wrote a code for implementing file I/O. this code contains two function - one used to write characters into text file, and the other used to read characters from text file. #define _CRT_SECURE_NO_WARNINGS #pragma once #include <iostream> #include <fstream> using namespace std; int writefile(const char* f) { int cnt...

Django views can't open .csv file by using pandas [IOError]

python,django,file-io,pandas,django-views
I got IOError when I open .csv file in views.py, it says I don't have the file in the directory, here is my directory: /survat #theproject /survatapp #theapp /modules __init__.py survat_core.py __init__.py views.py forms.py models.py prostate1.csv __init__.py settings.py urls.py wsgi.py /database sqlite.db /media /static /bootstrap Here is the traceback Environment:...

How to orchestrate members in a cluster to read new input from a single file once the current job is done?

file-io,fortran,mpi,fortran90
I am working on a global optimization using brutal force. I am wondering if it is possible to complete the following task with Fortran MPI file I/O: I have three nodes, A, B, C. I want these nodes to search for the optima over six sets of parameter inputs, which...

JAVA read text files, count numbers and write it to Jtable [closed]

java,swing,file-io,jtable
I am still learning JAVA and have been trying to find a solution for my program for a few days, but I haven't gotten it fixed yet. I have many text files (my program saves). The files look like this: text (tab) number (tab) number (tab)... text (tab) number (tab)...

Writing an object to python file

python,file-io
I have a following code: matrix_file = open("abc.txt", "rU") matrix = matrix_file.readlines() keys = matrix[0] vals = [line[1:] for line in matrix[1:]] ea=open("abc_format.txt",'w') ea.seek(0) ea.write(vals) ea.close() However I am getting the following error: TypeError: expected a character buffer object How do I buffer the output and what data type is...

Accessing open files globally in Fortran

file-io,fortran,gfortran
Is there any means to accessing (reading, writing to) files that are opened in some other source code by just passing the unit number?

How do I implement a timeout when using File.Copy?

c#,.net,file-io,io,timeout
I'm using System.IO.File.Copy to copy a file from a remote share to my local system. How can I implement a timeout if the copy takes too long?

How do EMACS Lisp programmers read text files for non-editing purposes?

file-io,emacs,elisp
What do EMACS Lisp programmers do, when they want to write something roughly the equivalent of... for line in open("foo.txt", "r", encoding="utf-8").readlines(): ...(split on ws and call a fn, or whatever)... ..? When I look in the EMACS lisp help, I see functions about opening files into text editing buffers...

indexing a text file into two arrays

c#,file-io,indexing
So I have a text file that holds 12,970 lines. I want to take this file and make them into two arrays, list, anything that will separate the file into two groups: group one being called apollo that holds the lines 0 through 7678 and group two being called sabre...

fdopen: Invalid arguement

c++,file-io
I am trying to create and open a file with fopen and fdopen to write some content. Below is the code I wrote: char Path[100]; int write_fd; snprintf(Path,100,"%s/%s","/home/user","myfile.txt"); printf("opening file..\n"); write_fd = open(Path, O_WRONLY | O_CREAT | O_EXCL, 0777); if(write_fd!=-1) { printf(" write_fd!=-1\n"); FILE *file_fp = fdopen(write_fd,"a+"); if (file_fp ==...

Finding a word in a text file

c#,list,file-io
So I have a large file text file, one that is 12,970 lines long. Within this insanely large data file I have two groups: one that is called A and one that is called S. A starts at line 1 and ends at line 7678. S starts on the next...

What is the best variant for appending a new line in a text file?

file-io,rust
I'm new to Rust, and I am using this code to append a new line to the end of file: let text = "New line".to_string(); let mut option = OpenOptions::new(); option.read(true); option.write(true); option.create(true); match option.open("foo.txt") { Err(e) => { println!("Error"); }, Ok(mut f) => { println!("File opened"); let size =...

Haskell return lazy string from file IO

haskell,file-io,lazy-evaluation
Here I'm back again with a (for me) really strange behaviour of my newest masterpiece... This code should read a file, but it doesn't: readCsvContents :: String -> IO ( String ) readCsvContents fileName = do withFile fileName ReadMode (\handle -> do contents <- hGetContents handle return contents ) main...

Trying to close multiple stream with finally

java,file,file-io,try-catch-finally
I have a program that open 3 streams of data but I do not know how to close all of them, here it is the closing part of the program. finally {//cerrando muestras try{ if(muestras!=null){ muestras.close(); } }catch (IOException e) { e.printStackTrace(); }finally {//cerrando salida try{ if(salida!=null){ salida.close(); } }catch...

Full path of HttpPostedFileBase is giving error with webclient upload file

c#,asp.net-mvc,asp.net-mvc-4,file-io,webclient
public ActionResult Index(PublishPost post, HttpPostedFileBase f) { string apiUrl = "http://myurl.com" WebClient Client = new WebClient(); byte[] rb = Client.UploadFile(apiUrl, "POST", f.FullName); string response = Encoding.UTF8.GetString(rb); } The path of httppostefilebase is showing -- C:\Windows\SysWOW64\inetsrv\adminrights.JPG but it is giving error with webclient - Path not found. Please help...

Python - find recurring pairs/groups of values in dictionary

python,sorting,file-io,python-2.6
I have the following script, which loops over a text file of css rules, and stores each rule and its properties in a dictionary(improvements to code welcome, I've only just started using Python): findGroups.py import sys source = sys.argv[1] temp = open('pythonTestFile.txt', 'w+') di = {} with open(source, 'r') as...

Writing out a specific line of a list

c#,if-statement,file-io,console
I have a large file, and I took that file and divided it into 2 groups: A and B. Below is a sample of each line in the file: 5/21/2015 11:55:56 PM | Batch 6|386/767|50.33 %|CH2M-R|Processed NXRMN5...Checking refundable and non-refundable fares. Traditional Booking. Inside ticketing window. Minimum Savings Required: $131.00....

Java: Create Directory with Loop

java,file-io
I make a program that create a directory on desktop with the name of world but i need 10 more directories in this world directory with the name of world1,world2 etc with the help of loop i enter loop but it doesn't create directories inside world. Code: public class A...

How can i access a js file in my project?

javascript,c#,c#-4.0,file-io,filestream
I want to read "script1.js" by filestream in my console application like below. But it returns to me an error. Is there any better way to read a js file in application, by using filestream it returns to me error: FileNotFound exception. ...

Loading mixed numeric and string data

matlab,file-io
I'm new to matlab. I have the a file named iris.data and I'm trying to load it's contents into variables. The file have the folowing contents: 5.1,3.5,1.4,0.2,Iris-setosa 4.9,3.0,1.4,0.2,Iris-setosa 4.7,3.2,1.3,0.2,Iris-setosa 4.6,3.1,1.5,0.2,Iris-setosa 5.0,3.6,1.4,0.2,Iris-setosa 5.4,3.9,1.7,0.4,Iris-setosa 4.6,3.4,1.4,0.3,Iris-setosa 5.0,3.4,1.5,0.2,Iris-setosa 4.4,2.9,1.4,0.2,Iris-setosa 4.9,3.1,1.5,0.1,Iris-setosa 5.4,3.7,1.5,0.2,Iris-setosa 4.8,3.4,1.6,0.2,Iris-setosa 4.8,3.0,1.4,0.1,Iris-setosa I tried: load iris.data But I got:...

C - Print the 5th letter of each word read from a text file

c,file-io,runtime-error
I wanted to find the 5th letter from every word after reading from the text file. I do not know where I am wrong. After entering the file path, I am getting a pop up window reading read.c has stopped working. The code: #include<stdio.h> #include<conio.h> int main(void){ char fname[30]; char...

Batch: find last line that starts with character then start reading from there

string,batch-file,file-io,last-occurrence
Good day, I want to know how do I create a batch script that searches through a text file that contains multiple lines that start with *==============. I wish for it to find the last occurrence of a line like this and then only use everything thereafter in the rest...

Algorithm to search regex pattern stuck for some txt

python,file-io
I created Unit Tests for algorithm to search regex pattern in txt files. It is stuck for some files during analysis of this regex: (nr|numer|[fj]ak[^\r\n]{1,3}ura)\s((?!kas|par|rej|kl\.|kont|te[lł]|klien|zlece|trans|zam|dz|pkwiu|wydr))?(?!rachunk|lic)(.*\n){5}` Test: def testNIPMass(self): #mypath="E:\\Skrypt\\txts\\1" mypath="C:\\Users\\lataman\\Documents\\OCR\\PyVer\\skrypt\\txts\\1" container=schemeContainer.createObject("PL") for f in listdir(mypath): file = join(mypath,f) if isfile(file): tArray=utilities.fopen(file).split('\n')...

When I write to two files in python, the second one is always empty

python,file-io
I'm working on a simple python script to write some data to two text files. My code looks like this: with open('file1.txt', 'w') as file1: for thing in stuff1: file1.write(thing + '\n') with open('file2.txt', 'w') as file2: for thing in stuff2: file2.write(thing + '\n') When I run the program, file1...

Node.js v0.10: Replace certain bytes in file without reading whole file

node.js,file-io
I am making a text editor and for editing a file I really need some sort of way to only read certain bytes from a file, which I've achieved using fs.createReadStream uisng the start and end options. I also need to replace certain bytes in the file. I am not...

Linux: Using split on limited space

linux,bash,file-io
I have a huge file on a linux machine. The file is ~20GB and the space on my box is ~25GB. I want to split the file into ~100mb parts. I know theres a 'split' command but that keeps the original file. I don't have enough space to keep the...

How to scan several drives for specific directories?

c#,file-io
I am not looking for specific files but rather specific directories to index all files in those directories. I am aware of how to search for file types and names but not how to do that with directories for indexing.

Getting Apache Camel to stop retrying if failed to move the file after route completion

java,file-io,exception-handling,locking,apache-camel
The example route below picks up a file and performs a series of operations on them. Once completed, as noted in the camel:from field, the route is instructed to move the file to a .processed directory. Alternatively if failed, move it to the .error folder. The problem occurs when another...

Segmentation fault when trying to allocate memory for a string via a pointer-to-pointer function call

c,pointers,file-io,segmentation-fault,malloc
I Initiate my string and call my function like this: int main() { ... char *fileBuffer; readFileToBuffer("/tmp/file.txt", &fileBuffer); ... } The purpose of this function is to get the contents of file.txt and put it into the fileBuffer variable. Because the content of file.txt is dynamic, I allocate the memory...

Cannot access LocalFolder files on Windows phone app (UnauthorizedAccessException)

c#,file-io,windows-phone
I am trying to get an application to write (then read) a simple text file in Windows Phone 8. My app has three controls: a create file button, a display file button, and a textbox where the contents are supposed to display. I have the following events set up in...

Greed on C Program trouble saving game to file

c,file-io
We're having this project of implementing Greed (greedjs.com) in C. everytime user makes a move, this function should update. as @ moves, it would leave the particular element of my BOARD[ROW][COLUMN] = 0. how can I write it into file so that instead of 0 it would print a space?...

Reading file data into cell array of character strings

arrays,string,matlab,file-io,cell-array
I'm new to matlab. I have files conatins list of string like: ABCCD HGAQ VBSER I need to read it into cell array of character strings. I tried this code: fid2 = fopen('C:\matlab\data\myfile.txt'); tline = fgetl(fid2); while ischar(tline) disp(tline) tline = fgetl(fid2); end fclose(fid2); However, I didn't know how to...

skip method in CipherInputStream

java,file-io,cryptography,inputstream
I am running into an issue where the code that works against a InputStream backed by a FileInputStream does not work if a CipherInputStream is used. Example is below: // skipCount is same as n in a FileInputStream FileInputStream fis; ... skipCount = fis.skip(n) Get a different behavior if a...

C++ efficient way to buffer text and conditionally write portions to a text file

c++,string,file-io
I'm constructing CSV text files containing hundreds of millions of lines. Each call to the record function forms a line of text and buffers it into a stringstream. Periodically, depending on the input to the record function, the buffered line(s) will either be written to file or discarded. I would...

Writing floats to a binary file in C++ | Equivalent of Java's DataOutputStream.writeFloat()

java,c++,file-io,binary
I'm porting some code from Java to C++ and need to write floats to a binary file. In Java I use DataOutputStream.writeFloat(). How do I do it in C++? I tried this method but it doesn't work: std::ofstream out; out.open(somePath, std::ios::out | std::ios::binary); float f = 0.5; out.write(reinterpret_cast<const char*>(&f), sizeof(float));...

Comparing strings of text files

c#,loops,if-statement,file-io,foreach
I have three text files: file1 file2 and file3 all of which contain emails. file1 is supposed to have all the emails in there, file2 has all emails that are A-M, and file 3 have emails from n-z (This is not important but I figure it would help give a...

File handling Code compiles but does not run

c,file-io
Well what i'm doing is basically i'm reading a file, saving it to an array, and try to print it. But what does seem to be a problem on my code? #include<stdio.h> #include<string.h> typedef struct{ int studentNumber; //struct declaration char name[31]; float quizzes[8]; float exams[3]; float overallGrade; float standing; }Student;...

Java FileOutputStream Created file Not unlocking

java,file-io
Currently am facing a problem with FileOutputStream in my code used FileOutputStream for creating file in my disk .Once file created there is no way for opening , deleting or moving file from its location ,getting error message already locked by other user When stopped web server it working properly...

Get specific entries from .dat file with COBOL

file-io,cobol
I'm new to COBOL and having trouble to search specific entries in a .dat file. The idea is to search the file for all the records that have a certain code in one of the fields. I've tried to find the answer in google but everywhere I went the answer...

Creating custom std::streambuf

c++,file-io,stl
I am defining a custom std::streambuf class for use in file I/O. In this class, I am overloading the functions open, close, is_open, xsgetn, xsputn, overflow, underflow, and uflow. I then insert this buffer into an std::ifstream as follows (the same scenario holds for std::ofstream): std::ifstream temp; Filebuffer *buffer =...

C - dynamically modifying a file - is it possible?

c,file-io
I'm writing a small program in C and I want to have the option of saving data to file and then reading it from that file. The data is BIG, so I want to somehow dynamically write to a file without having to create a new file and copy modified...

java.nio.file.NoSuchFileException: why nio not creating file [closed]

java,file-io,nio
I am using java.nio.file package and tried to create file with the following code. private static void printReport(String filename, String str)throws Exception{ ErrorCheck ec = new ErrorCheck(); String fileName = "/var/Emails_log/"+filename; Path filePath = Paths.get(fileName); File file = new File(fileName); final BufferedWriter out = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8, StandardOpenOption.APPEND); try{ final Path...

Write to specific part of preallocated file

ruby,file,file-io,seek
I am currently trying to write to different locations of a pre-allocated file. I first allocated my file like so: File.open("file", "wb") { |file| file.truncate(size) } Size being the total size of the file. Afterwards I receive data of XX size which fits into Y location of that file. Keep...

Not checking file size correctly

python,file,python-3.x,file-io,operating-system
I wrote a simple script to move movies in my downloads directory, once they are finished downloading, to the location they need to go and have a simple question regarding it. Maybe I'm not understanding how the os module is working to the current size of the file here, but...

Non-OS Specific FD(File Descriptor) for C/C++

c++,design-patterns,asynchronous,file-io,network-programming
Linux is also treated as a file, a network socket. but, Windows is not. and common files and network sockets treated as "FD". if the code should not rely on the operating system, how should write? i think it like below.. #ifndef INVALID_SOCKET #define INVALID_SOCKET (-1) #endif class Descriptor {...

How to output data to file in matlab?

matlab,file-io
I've read several articles about how to output data to file, but it just doesnt seem to work for me. I have output.txt file at the same folder as my matlab file resides and it just doesn't output any data to that file? What is wrong with it? I want...

Troubles reading a single character from a text file

java,file-io
I'm writing an "app" that takes in time input from the user and stores the hours and the minutes separately for each day in a text file (giving a result that looks like: day 1: 8h 45min day 2: 8h 43min ... ) the idea behind it is to use...

Read file, check correctness of column, write file C#

c#,visual-studio,file-io,delimiter
I need to check certain columns of data to make sure there are no trailing blank spaces. At first thought I thought it would be very easy, but after attempting to achieve the goal I have got stuck. I know that there should be 6-digits in the column I need...

Reading only first integer from whole line in text file

c++,file-io
If have text file like this: 3 size of group 10 individual therapy time(min) 15 group therapy time(min) 25 new client probability percentage 500 individual therapy cost 300 group therapy cost is there a way to just read first integer of text line and jump to other line? What I...

Ruby - How to subtract numbers of two files and save the result in one of them on a specified position?

ruby,file,file-io,append
I have 2 txt files with different strings and numbers in them splitted with ; Now I need to subtract the ((number on position 2 in file1) - (number on position 25 in file2)) = result Now I want to replace the (number on position 2 in file1) with the...

Does separating read/write operations improve program efficiency?

java,algorithm,performance,file-io,data-structures
I've written a program for class which takes in data from a URL, parses it for key phrases and then writes to a text file the phrase, line number, and column number. Currently I am doing this as a single operation where the URL is fed to a BufferedReader for...

Cakephp Version 2.x Unable to Show selected file name in edit view

php,cakephp,file-io,editview
Hopefully this is a simple issue. I have a Cakephp MVC set to upload an image and store it in a database table. Index, View and Add are working as I want. However, in the Edit view how can I indicate that the record currently has an uploaded image that...

reading from txt file into dynamicly allocated

c,file-io,struct,dynamic-memory-allocation
I want to read some data from txt file and store it in s_person struct and than print it latter. Text file structure looks like this: john 43 23 steven 23 44 micheal 11 0 Variable array is for those 2 numbers next to name in txt file. #include<stdio.h> #include<stdlib.h>...

populate a 'JTable' with values from a '.txt' file

java,swing,file-io,jtable,stringtokenizer
I'm new to java and I have a text file like this 0786160384|P. K.|Tharindu|912921549v|Colombo| 0711495765|P. K.|Gamini|657414589v|Colombo| 0114756199|H. P.|Weerasigha|657895478v|Kandy| I want to populate my 'jTable' with with the data from this text file. below is my code so far which doesn't work. When I execute the program nothing is displayed on...

Get Video File and save using c#

c#,asp.net-mvc-4,video,file-io
I am working on MVC4 web api,where I need to get video file from server path("C:\web_app\content\video\demo.mp4") and need to save that video to the different location("C:\video\demo.mp4").Video format is "MP4". Thanks in advance....

Should I fclose(file) if an error occured?

c,file,file-io,fopen,fclose
Code: FILE *fp = fopen(filename, "r"); if (!fp) { fprintf(stderr, "Failed to open a file\n"); // fclose(fp) <-- should I close file here? exit(1); } // Some operations on the file. fclose(fp); Question: If fopen() fails to open a file, should I still call fclose()?...

PHP read txt from specific line to the end

php,file-io
In the following, $mensaxe reads the second line of a .txt file: function getMessageList(){ $this->messageList = array(); if ($handle = @opendir($this->messageDir)) { while ($file = readdir($handle)) { if (!is_dir($file)) { $this->messageList[] = $file; } } } rsort($this->messageList); return $this->messageList;} function displayGuestbook($page=1){ $list = $this->getMessageList(); $startItem = ($page-1)*$this->itemsPerPage; if (($startItem +...

FileOutputStream writing less than it should

java,file,file-io,fileoutputstream
I am trying to write a program that save into a .txt the data of a sinwave but when I execute the program it writes less (sometimes even nothing) that it should. Here is the code: public static void main(String[] args) { GeneradorSeñal gs = new GeneradorSeñalSinusoidal("sgsg"); Double salida; try{...

Create file that the application can edit but the user cannot

c++,file-io,stdio
I'm making a scored game, and want to save the high scores. I want to save the scores in a file that the program can access (of course), but the scores shouldn't be editable by the user (a read-only file, probably). The problem with a read-only file is that, obviously,...

Taking a file and splitting it into 2 groups

c#,list,file-io
So below I have a piece of code that will take a data file and split into two groups, a and b. string path = @"c:\users\povermyer\documents\visual studio 2013\Projects\DanProject\PNRS\PNRS.log"; string[] lines = System.IO.File.ReadAllLines(path); var count = File.ReadLines(path).Count(); List<string> groupA = lines.Take(7678).ToList(); List<string> groupB = lines.Skip(7678).Take(5292).ToList(); For clarification, the first group takes...

Unable to modify variables from separate thread

c#,multithreading,winforms,text,file-io
So I'm making a C# app which has to continuously read and display the contents of a text file, while allowing the user to enter something into a text box and append it to the end of that very file. I'm doing this by running my read method on a...

dojo 1.10 How to read text file a user has picked with a file picker

javascript,file-io,dojo
Using Dojo 1.10 (for consistency with existing GUI), I want the user to select a local JSON text file via a file picker, then read the file's contents into a JavaScript variable. Must work in IE9+. A RESTful server is available if required, but not mandatory. I had some limited...