FAQ Database Discussion Community


Read a file selected by user in Javascript?

javascript,jquery,file-get-contents,readfile
I have looked around for a while and still haven't found a satisfactory simple answer to this (thought as popular) problem. The solutions are either directed to sending the file directly to the back-end or way too complex. I have this: $("#"+id+" input").change(function() { file = $(this).prop('files')[0] var reader =...

How to read files from my bin directory in my Tomcat folder in a Spring MVC application?

java,spring,spring-mvc,tomcat,readfile
How can I read files into an InputStream in my Spring MVC application from the /bin directory in the applications Tomcat folder? How can I tell what the relative path would be? Would I need something similar to FileInputStream.class.getResourceAsStream("/bin/FILEHERE.p12"); The files I need to read are p12 certificate files....

Read lines from file not return all

c,fopen,readfile,fgets
I'm trying to keep the words from a file into an array but I only read the first 8. My code below. #define BUF 128 /* can change the buffer size as well */ char ** readFileContentArray(char* filename){ int lines = 128; char ** strLines = (char **)malloc(sizeof(char*)*lines); FILE *plist...

read in MIPS file opened in C

c,mips,readfile
i have a c function where i open and close a file. But i want to replace the fgets function for a custom readFile function implemented in MIPS. According to: When reading file in MIPS, it reads last line twice and http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html i need to pass the syscall the code...

C# Making a clickable list with names from a specific folder

c#,list,directory,readfile,clickable
Ive searched high and low for this but cant find it. Im trying to make a list with names from a specific folder that holds a lot of text files. I want the list to be clickable so let's say if it show a name like "Name1" and i click...

Get content from Json file inside the project

c#,json,file,windows-phone-8,readfile
I'm trying to get content from file which is located in my project. But all the time I got "Could not find a part of the path " using (StreamReader r = new StreamReader(Directory.GetCurrentDirectory() + @"/Resources/Database/questionsTEST.json")) My JSON file is located in Resources/Database/questionsTEST.json. I try also with test.txt located in...

open text file as input to textblob

python,readfile,textblob
hello it's my first question so my deepest apologies if i didn't go by a rule or so, i 'll try my best to make it as clear as possible i am trying to use textBlob with a text file input all examples i found online were of input in...

C# .NET ReadFile from USB AccessViolationException was unhandled

c#,.net,usb,dllimport,readfile
I am receiving an AccessViolationException when calling the ReadFile API. I have looked at all of the entries on StackOverflow dealing with similar issues and have not had any success deciphering what is wrong. Here is the relevant code in question: INVOKES [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public...

R read file with curly braces

r,readfile
I have a following txt file: Header1 Header2 Header3 1 5 {Joe, John, Sam} 2 9 {Mike} 3 5 {Bob, Alice} I am trying to read it with following command, but it gives an error: data = read.table("file_location/data.txt", sep=" ", strip.white=TRUE, header=TRUE) more columns than column names How can I...

read in file in python

python,file,io,readfile
I have a function in python that parses in a file that looks like this: Led Zeppelin 1979 In Through the Outdoor -In the Evening -South Bound Saurez -Fool in the Rain -Hot Dog -Carouselambra -All My Love -I'm Gonna Crawl Led Zeppelin 1969 II -Whole Lotta Love -What Is...

Python - Read specific lines in a text file based on a condition

python,file,line,readfile
Problem Statement: I have a file as below. name | date | count John | 201406 | 1 John | 201410 | 2 Mary | 201409 | 180 Mary | 201410 | 154 Mary | 201411 | 157 Mary | 201412 | 153 Mary | 201501 | 223 Mary |...

Read Same Text File in Different Methods

c#,winforms,text-files,readfile
In the BtnNext_Click method it's just reading from the text file like it was a different text file, and not from the one that already was opened. It does not go from line to line. I need help Here is the code: public void ScrubData() { string FileName1; string FilePath1;...

Reading only str objects from a file

python,random,readfile
So while working on my program I'm trying to read a file, bring back all the information contained. While another function splits the list and random generates a string contained. If it's not a string, try again. Unfortunally my program flips out while doing this and completely refuses to obey...

Searching words in a file with C++ language

c++,string,readfile
I'm editing my post with the progress I made so far. Well, what I want to do for now is: Read the text file from the first line without astherisc (*), aka the line begging with number 1, to the end of the file. When there is a "blank space"...

Haskell read multiple files

haskell,readfile
I'm trying to read multiples files at once using the following code. The code compiles, however when executed I get the following exception: *** Exception: ..: openFile: permission denied (Permission denied). I have all the permissions as system administrator. Also, I was able to do the same in C# with...

Can't find Json file inside project

c#,json,file,windows-phone-8,readfile
I'm trying to read a json file from my project but vs can't find it. When I'm using the .txt extension, everything is OK, but when I change extension to .json, then the file is not found string fileContent; StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Resources/Database/text.json")); using (StreamReader sRead = new...

Reading a text file with Tabs

c#,asp.net,.net,file,readfile
In a text file I use TAB to create a column-like grid, but apparently those tabs are just read as spaces, which of course breaks the formatting. This is my code (path is the file path, e.g. D:/folder/testtt.txt): if (File.Exists(path)) { using (TextReader tr = new StreamReader(path)) { while (tr.Peek()...

fgets not reading complete line in C

c,pointers,readfile,fgets,coredump
I have a file data.csv which contains float type data: 0.22,0.33,0.44 0.222,0.333,0.444 I need to read this file into a two dimensional dynamic array. But I am not able to read the full line with fgets. Not sure why? Here is my C code which I used on Ubuntu: #include...

RainMeter multiline - RegExp

regex,readfile,rainmeter
I'm trying since a couple of days to read an entire file with Rainmeter. I'm working with WebParser and RegExp. My result is something like this: Line1 Line2 Line3 If I make a RegExp like (?m).*, I have only the first line. However, if I use something like (?m).*\n.*, I...

Loading multiple files Exception error C#

c#,exception,readfile
I am making the game minesweeper and I am trying to implement a highScores feature. I am trying to load 3 different files (each one holds the high scores for each of the 3 difficulty settings) into 3 different richTextBox's. When I run the app and click the 'high scores'...

Textscan Matlab ; Doesn't read the format

matlab,readfile,format-specifiers,textscan
I have a file in the following format: **400**,**100**::400,descendsFrom,**76**::0 **400**,**119**::400,descendsFrom,**35**::0 **400**,**4**::400,descendsFrom,**45**::0 ... ... Now I need to read, the part only in the bold. I've written the following formatspec: formatspec = '%d,%d::%*d,%*s,%d::%*d\n'; data = textscan(fileID, formatspec); It doesn't seem to work. Can someone tell me what's wrong? I also need...

Win32 ReadFile Output without waiting for buffer

c++,visual-studio-2012,readfile
I run a command to cmd.exe with CreateProcess(). The command itself has an endless output, so I use a function that I modified from this answer to get partial outputs into a string. #define BUFSIZE 4096 HANDLE g_hChildStd_OUT_Rd = NULL; std::string ReadFromPipe(PROCESS_INFORMATION piProcInfo) { DWORD dwRead; CHAR chBuf[BUFSIZE]; ReadFile( g_hChildStd_OUT_Rd,...

How do I stop reading a line when I encounter a whitespace?

c++,c,ifstream,readfile
I'm opening a file and reading it using getline(x,y) currently but I want to stop reading the line when I encounter a whitespace and then continue reading from there. Thanks

How to assign text file data to variable

c,readfile
I am trying to read from a text file and assign that to a variable. At the moment I have it at the stage where it reads from the file and prints it out, however I haven't figured out how to assign the result to a variable. This is my...

createReadStream in Node.JS

javascript,node.js,file,stream,readfile
So I used fs.readFile() and it gives me "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory" since fs.readFile() loads the whole file into memory before calling the callback, should I use fs.createReadStream() instead? That's what I was doing previously with readFile: fs.readFile('myfile.json', function (err1, data) { if (err1)...

Not able to read file data after counting number of lines

python,readfile
import sys source = open(sys.argv[1], 'rt') count_lines = len(source.readlines()) print count_lines for row in source: print row source.close() I am trying to count the number of lines in a file and then reading the file line by line. count_lines returns the correct value but there is no output from print...

readfile download a blank/empty file

php,download,readfile
I'm trying to use readfile to download a file from the server. The file definitely exists and when I use the URL in browser directly it downloads the correct file as predicted. However when I do it with the following code, it download the file with the correct filename but...

Powershell comparison of text file

powershell,readfile
I'm just wondering if it's possible to compare two text file and check if there's a difference between them? What I mean is like this, For example I have text1.txt : 123 456 789 000 and I have text2.txt : 123,test,input,bake 789,input,cake,bun Expected output : 456 does not exist in...

Don't write text into my txt file

java,readfile,writefile
With this code I want to read one text file, put all elements into a arraylist and replace the file with the the arraylist contain. But this code don't write into file and I don't know why... public void delete(String lineToDelete, String nameFile) throws IOException { file = new File(nameFile);...

what is the fastest way to get dimensions of a csv file in java

java,csv,readfile
My regular procedure when coming to the task on getting dimensions of a csv file as following: Get how many rows it has: I use a while loop to read every lines and count up through each successful read. The cons is that it takes time to read the whole...

Reading file into HashMap

java,hashmap,readfile
I am reading a file with the city and its population. the file looks like this: New York city NY 8,175,133 Los Angeles city CA 3,792,621 ............ The format of the original file is different but I can't modify my code to read it properly. The original file looks like...

difference between readlines() and split() [python]

python,readfile
imagine we have a file = open("filetext.txt", 'r') what is the difference between the split() method and the readlines() method It seems that both split each line and put it as a string in a list. so what makes them different ? for line in file: values = line.split() #break...

is the overlapped structure updated when using ReadFile?

c++,winapi,readfile,overlapped-io
I'm learning something on win32 programming. I read on the reference manual (here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx ) that If lpOverlapped is not NULL, the read operation starts at the offset that is specified in the OVERLAPPED structure and ReadFile does not return until the read operation is complete. The system updates the...

How to import efficiently values in Python from a list of global variables in a C header file

python,header,global-variables,readfile
I would like to find an efficient and quick way to load the values of a list of global variables from a C header file into Python. For instance, suppose I have the file header.h: /* comments */ int param_nx=2049; // comment int param_ny=2049; // comment double param_dt=0.01; // comment...

while(getline(myReadFile, temp, ':')) executing one iteration too many causing out of bounds on vector

c++,readline,readfile
I have a question on std::readline(istream, string, delimiter). I am trying to read in a file and store the data in a struct and add it to a map. That I have gotten to work. However my while loop iterates one loop too many causing my vector to have no...

Ignore certain words when reading a file

java,readfile
My program reads a text file and lists the frequencies of each word in the file. What I need to do next, is ignore certain words such as 'the','an' when reading the file. I have a created a list of these words but not sure how to implement it in...

How to change a php read file using jscript and php. New Q how to stop it effecting the header

php,html,mysql,redirect,readfile
Note this still does not work as intended it does not put the information into the page instead it just redirects to a new page Update New problem is that I dont want the user seeing a massive header that is my reason for using this readfile system is there...

python - Read file using win32file.ReadFile

python,readfile,pywin32
Similar Question: What's the correct way to use win32file.ReadFile to get the output from a pipe? The issue I have however was not answered in that question. When I call result, data = win32file.ReadFile(my_file, 4096, None) result is always 0 which according to documentation means success: The result is a...

how can i use ruby and twitter tweet from text file

ruby,file,twitter,readfile,tweets
I'm trying to tweet from a text file without getting the extra symbols. My tweets looks like: ["This is a sample of my tweet on twitter"\n] << it includes the symbols and the extra "n". What I'm trying to get is: This is a sample of what I want my...

reading txt file with numbers and saving in it in a String Matrix

java,eclipse,matrix,readfile
Im trying to read a txt file with numbers and saving each number in a String matrix but there some things i dont get. 1.-If i run the code in Eclipse i get printed like 16 times everything and the numbers get smaller and smaller.. 2.-After beeing printed there...

Node error while trying to read file from file system - Can't set headers after they are sent

javascript,jquery,node.js,express,readfile
I use node FS module to read file from my C drive The problem is that in the console I got the following error: Can\'t set headers after they are sent 12345 _http_outgoing.js:335 throw new Error('Can\'t set headers after they are sent.'); ^ Error: Can't set headers after they are...

How to add tuples to list after reading from a text file in Haskell

list,haskell,tuples,readfile
I am trying to create a program in Haskell that reads text from a text file and adds them to a list. My idea is: type x = [(String, Integer)] where the String is each word from the text and Integer is how many times that word occurs in the...

using ruby to delete duplicate words from text file

ruby,delete,duplicates,readfile
how would i use ruby to delete duplicate lines of word from a text file? for exmaple: file reads = line 1 = 345 line 2 = 234 line 3 = 456 line 4 = 789 line 5 = 234 line 6 = 345 I'm trying to write a script...

Looking for a way to speed up the write to file portion of my Python code

performance,python-3.x,readfile,writefile
I have a simple code that reads in a data file ~2Gb, extracts the columns of data that I need and then writes that data as columns to another file for later processing. I ran the code last night and it took close to nine hours to complete. I ran...

How do I read a text file into a string variable in Python starting at the second line? [closed]

python,string,list,python-2.7,readfile
I use the following code segment to read a file in python file = open("test.txt", "rb") data=file.readlines()[1:] file.close print data However, I need to read the entire file (apart from the first line) as a string into the variable data. As it is, when my files contents are test test...

Reading several text files, the last one in the row is not read

java,readfile
Im trying to read 100 text files from a folder and save them to a matrix, and it works perfectly for the first 99 text files. This could be a trivial mistake, but I can not find it. Thank you in advance! package mba_prob; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern;...