FAQ Database Discussion Community


How to improve the performance of Haskell IO?

haskell,io
It seems that Haskell's IO is relatively slow. For example, comparing Haskell with Python #io.py import sys s=sys.stdin.read() sys.stdout.write(s) , -- io.hs main = do s <- getContents putStr s Their performance (gen.py writes 512k data into stdout): The Python version: $ time python gen.py | python io.py > /dev/null...

Faulty file in use error

c#,winforms,io
This code is the first code in my Form_Load method: DirectoryInfo dir =new DirectoryInfo("d:\\themes.thumb"); string[] animals = new string [] { "Snakes", "SnowyOwls", "Tigers", "TropicalFish", "WildBeauty", "Wolves" }; foreach (FileInfo fil in dir.GetFiles()) { for(int ii=0;ii<animals.Length;ii++) { if (fil.Name.StartsWith(animals[ii])) { try { fil.Replace(fil.FullName,fil.FullName.Replace(fil.Name,"Animals-" + fil.Name)); } catch { } }...

ResourceNotFoundException on existing path

java,io,velocity,resource-loading
I have the following class: public class EmailService { static { Velocity.setProperty("resource.loader", "class"); Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.init(); } public void sendTerminalModerationStatusChangedEmail(Terminal terminal, String to) { ... Template subjectTemplate = null; try { subjectTemplate = Velocity.getTemplate(existedPath, "UTF-8"); } catch (URISyntaxException e) { e.printStackTrace(); } ... } } In debug I see that...

how to save information from a file in java

java,string,file,io
I am supoose to read a file lets say it has 3 lines: 2 Berlin 0 2 2 10000 300 Nilreb 0 2 2 10000 300 the first integer number shows how many names(lines) i have. the 2nd and 3rd lines show information about two post offices. them i am...

Custom streambuffer in std::ofstream

c++,io,streambuf
I know that in std::ostream, I can use a custom streambuf through either stating so in the constructor: std::ofstream temp; temp.open("file.txt", std::ios_base::in); std::ostream example(temp.rdbuf()); as well as by setting it afterwards (same first two lines as before, but change the last line to: std::ostream example; example.rdbuf(temp.rdbuf()); My question is: How...

perl: canot open file within a loop

perl,io
I am trying to read in a bunch of similar files and process them one by one. Here is the code I have. But somehow the perl script doesn't read in the files correctly. I'm not sure how to fix it. The files are definitely readable and writable by me....

C# Linq Dictionary IO

c#,linq,dictionary,io,statistics
How can I do this with LinQ? I have a txt file.(Its about 100 lines long.) 6 7 0/3 # ##t#kon tu#i#do#b#n ko#yk####a#s##ttak###lk##ul$$$$#$#$$$####$$$$#$$$$$$#$$#$$$$$#$ I stored it in a Dictionary (The two lines). alap = File.ReadAllLines("veetel.txt"); Dictionary<string,string> statisztikaDictionary = new Dictionary<string,string>(); for (int z = 1; z < alap.Length; z+=2) {...

ruby: running a command from a forked child process

python,ruby,ssh,io,fabric
I've the following snippet of code: job1 = fork do ret = `some_bash_script_running_python_fabric_task` end Process.detach(job1) This code is aimed at daemonizing a process, so the parent exits while child keeps running in background. I get as a result a python exception stating termios.error: (5, 'Input/output error'). I figured out that...

Reading a file in C and passing the contents to main()

c,arrays,file,io
I'm new to C. I'm having an issue accessing the data read in from a file. The idea behind what I'm trying to do is get a text file, read it in, create an array and set the contents of that array equal to the contents of the file (the...

unreported exception filenotfoundexception [closed]

java,io
I am trying to make a stream, so I can read 2 lines from .txt file to two string variables. I tried try/catch, but still have an ureported exception error. public class Shad1 { public void myMethod()throws FileNotFoundException { String stringName = new String(""); String stringNumb = new String(""); File...

Python subprocess input is read twice

python,io,subprocess,stdin
I need to wrap a program in python and feed it input and print output. But if it give it one line of input it seems to use this as input until the program terminates. I've written a very basic program in C (called inout) which takes in two lines...

In the dart:io library, why would one want to set runInShell: true when calling Process.run?

shell,process,io,dart
What functionality does this offer? Furthermore, how does the process get called when runInShell is set to false? What's the difference?

How to grep a string in a program?

c,linux,io,grep,pipe
#include <stdlib.h> int foo(char *str_buf_to_grep) { // How to write the following line correctly? return system("??? str_buf_to_grep ??? | grep mykeyword"); } Description: The str_buf_to_grep is given in any way, which might be the content of a text file, and might be very long and complex, even contains special characters,...

writing and reading a txt content using java

java,io,bufferedreader
I want to read data from a text file and columns are seperated by a space like this 1 BNA 5000 10.81 1 CER 1000 20.33 1 ADV 500 1.91 1 MNT 20000 5.53 and I want to write data----------------- to a text file in the same format,, and it'd...

How can I redirect, in Go, the stdout and stderr of a command to both the console and a log file while outputting in real time?

go,io,sync
The following bit of code does exactly what I want, except it only prints to the console. cmd := exec.Command("php", "randomcommand.php") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { log.Fatal(err) } randomcommand.php: // randomcommand.php simply alternates output between stdout and stderr 20 times $stdout...

Line wont split into array

python,file,python-2.7,io
When getting a line from a file and splitting it tells me this: Traceback (most recent call last): File "C:\Users\service user\Desktop\cmd\main.py", line 94, in <module> start() File "C:\Users\service user\Desktop\cmd\main.py", line 66, in start e = f.split('/') AttributeError: 'file' object has no attribute 'split' My code is here: if split[0] ==...

Are fputwc and fgetwc significantly faster than fprintf and fscanf? Why is it so?

c,performance,io,wchar-t
I am working on files using characters of wcahr_t type. I would like to make my program faster. Does it make any sense to substitute fprintf with fputwc and fscanf with fgetwc wherever possible? If so, why?...

the use of fflush(FILE* stream)

c,io,fflush
I Really can't understand the use of the : fflush() function , could I find a good implementation of this function ? I read some resources about it but I still can't grasp it well , actually I want to know what this function really do ?

Parsing text file lines into numbers using std::iter::Iterator map

file,text,io,rust
I'm trying to read and parse a text file in Rust. Each line is a signed integer. I'm able to do it using for line in lines iteration but I'm unable to do it with a iter().map(|l| ...) one-liner. I'm getting a expected `&core::result::Result<collections::string::String, std::io::error::Error>`, found `core::result::Result<_, _>` when I...

where is the text printed by C printf

io,common-lisp,cffi
I happened encounter a trouble with calling C printf function from SBCL via cffi. The problem is when I call printf function, I can't find the output text, just the return value of printf function show on the REPL. But when I quit SBCL, the output text appears on the...

Why I am getting shifted output when write to a text after converting it to xls file in java [closed]

java,excel,csv,io,html-parsing
I am writing outputs of parsed web pages into two text files. "CrawledURLS.txt" saves the crawled pages and "CrawledURLSERROR.txt" saves uncrawled we pages. Since i should get some plot of output data, i converted the .txt files to .xls file. I am getting more than "300.000" URLs. When i stop...

ERROR ITMS-90092: “This bundle is invalid…" [duplicate]

xcode,io,armv7,submission
This question already has an answer here: ERROR ITMS-90092: “This bundle is invalid. Apps that include an arm64 architecture are required to include an armv7 architecture.” 2 answers When I try to submit my Xcode I receive this error: ERROR ITMS-90092: “This bundle is invalid. Apps that include an...

OutputStream class is used for writing into files. How is it possible?

java,io,outputstream
The below code is quoted from : http://examples.javacodegeeks.com/core-java/io/fileoutputstream/java-io-fileoutputstream-example/ Although the OutputStream is an abstract method, at the below code, OutputStream object is used for writing into the file. Files.newOutputStream(filepath)) returns OutputStream. Then, the type of out is OutputStream, and out references OutputStream. How can this be possible while OutputStream is...

C - does read() add a '\0'?

c,unix,io,posix,unbuffered
Does it have to? I've always been fuzzy on this sort of stuff, but if I have something like: char buf[256]; read(fd, buf, 256); write(fd2, buf, 256); Is there potential for error here, other than the cases where those functions return -1? If it were to only read 40 characters,...

java.nio.charset.MalformedInputException: Input length = 1

java,io,character-encoding,malformed
I have this (stripped the HTML tags for the code example) function that builds a HTML table out of a CSV, but I get a runtime error everytime I try to run it and I don't know why. Google says that maybe something with the encoding is wrong but I...

how to effectively write text file in C and the size of file would be 5GB

c,io
FILE *fp; fp = fopen(pch, "wb"); while(1) fwrite(p, sizeof(char), strlen(p) / sizeof(char), fp); I used these codes to write to txt file, however when the output file is very big (It's size may grow up to 5GB) it will be very slow, I need to wait a long time. Can...

Appending lines for existing file in python [duplicate]

python,file,python-2.7,io
This question already has an answer here: How do you append to a file in Python? 6 answers I want to add lines to an existing file in python. I wrote the following two files print_lines.py while True: curr_file = open('myfile',r) lines = curr_file.readlines() for line in lines: print...

Output EOF using %f

c,io,printf,eof,format-specifiers
#include<stdio.h> int main() { printf("%d",EOF); } generates -1 which is totally fine, but #include<stdio.h> int main() { printf("%f",EOF); } produces 0.000 . How can someone explain this when the expected output is -1.000?...

Golang file reading only reading last line

csv,go,io,file-read
So I took some publicly available data that looks like this - this is the file http://expirebox.com/download/b149b744768fb11aee9c5e26ad409bcc.html ,,,% of Total Expenditure,,, Function Code,Type of Activity,Expenditure,Dollars/Student (ADA),"This District (ADA 49,497)",All Unified School Districts,Statewide Average 1000-1999ÊÊ,INSTRUCTIONÊÊ,"$249,397,226","$5,039",42%,62%,62% 1000,Instruction,"$247,472,790ÊÊ","$5,000",42%,48%,49% 1110,Special Education: Separate Classes,"$1,004,074",$20,N/A,N/A,N/A 1120,Special Education:...

how to read in files made of double values line by line using c++

c++,io
I'm trying to do something very simple, but just can't get it right... Working with C++, I want to read in "myfile.tsv" which looks like this: 2.3 3.3 3.4 3.5 5.6 \n 1.2 1.3 1.2 \n 3.4 3.5 3.5 \n 4.4 4.6 1.3 1.5 \n ... many lines of double...

Take C++ program output as Java input

java,c++,linux,io
I have a situation where I'm looking my Java program to run as BASH script which is turn will run a C++ program. I am looking to take the output of the C++ program (plain text strings printed to terminal) as input to the Java program. My first attempt was...

In Yesod/Haskell, how do I use data from IO with the variable interpolation functionality?

haskell,io,monads,yesod
How do I take values from an IO monad and interpolate into a yesod widget? For example, I want to interpolate the contents of a file into hamlet: (readFile "test.txt") >>= \x -> toWidget $ [hamlet| <p> text: #{x} |] or equivalently: contents <- (readFile "test.txt") toWidget $ [hamlet| <h2>...

Directory not empty java.io.IOException

java,osx,io,external,runtime.exec
I need to launch an external app called TeamViewer from my JavaFX application. So I've TeamViewer.app file which I'm copying to a temporary folder and launching it using: Runtime.getRuntime().exec("open /path/to/Teamviewer.app"); But this is throwing Directory not empty IOException. I also tried launching using shell file where I wrote "open /path/to/Teamviewer.app"...

Find and append to file without loading it in memory?

c#,.net,file,io,stream
Im writing a simple XML file for logging that looks like this : <root> <objects> </objects> </root> The file is created the first time like this using (xmlWriter = new XmlTextWriter(filePathAndName, System.Text.Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("root"); xmlWriter.WriteStartElement("objects"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } Now I need to place...

Apache POI is extremely slow

java,excel,io,apache-poi
I have seen many questions online about Apache POI performance, but none of them is as slow as my case and none of their solutions works for me. I am using NetBeans 8.0.2, JDK 1.8 and POI-3.12-20150511. To read a 300 KB xls (with 3000 rows and a few columns),...

Sequential file IO from different threads fail with FileSystemException

java,multithreading,windows-7,io
I am trying to see how fast i can do something like: write a small file rename it delete it This basically looks like: import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class QuickIO { public static void main(String[] args) throws IOException { Path fileToWriteTo = Paths.get("C:\\Temp\\somefile.txt"); Path fileToMoveTo...

How to read, filter and modify lines from a file

filter,io,rust
How to do something similar to this D and Java code in Rust? Java: import java.nio.file.*; import java.io.*; public class Main { public static void main( String[] args ) throws IOException { Files.lines(Paths.get("/home/kozak/test.txt")) .filter(s -> s.endsWith("/bin/bash")) .map(s -> s.split(":", 2)[0]) .forEach(System.out::println); } } D language: import std.algorithm; import std.stdio; void...

how to write the output of iostream to buffer, python3

python,string,io,stream,wrapper
I have a program that reads data from cli sys.argv[] and then writes it to a file. I would like to also display the output to the buffer. The manual says to use getvalue(), all I get are errors. Python3 manual import io import sys label = sys.argv[1] domain =...

How to get the screen shot of the window on mac?

io
I am trying the take the screen shot of the window in mac. I can either take the screen shot of all screen or none. But i only want to take the screen shot of window. Any help appreciated

select() function for simultaneously I/O

python,multithreading,sockets,select,io
I am trying to implement a multi-threading server which can handle with simultaneously read/write from client. The server method: The client connects to the server, when each message starts with the name of the user they want to send the message to, followed by '|'. It looks something like that:...

Reading unformatted name/value pairs from a file, formatting it, and printing it out in Python 2 dictionary [closed]

python,python-2.7,dictionary,io
Given a text file like so # Name_value_pair.txt name1 = value1 name2 = value2 name3 = "some value3" name4=value4 name5= name6 Is it possible to read that file, format it into a dictionary and print it out using python? I know how to open and read the files, but I...

Trying to use output of one function to influence the next function to count words in text file

python,file,python-3.x,io,count
I'm trying to use one function to count the number of words in a text file, after having this text file "cleaned" up by only including letters and single spaces. So i have my first function, which i want to clean up the text file, then i have my next...

How to read a middle size-specified chunk of a file in Python

python,io
If I have a text file, what is a clean way to start from a line at near the 5th MB into the file and read the subsequent 5 MB worth of lines into a list? Ideally into a list of lines. I know f.seek(5000000) starts at the 5th MB,...

read() : Invalid arguments

c,io
I'm trying to read a binary file with read() on a well functioning open()returned file descriptor but it just doesn't work returning 22 with errno. Here is the code : int input = open(argv[1], O_RDONLY|O_DIRECT); char buffer_header[4]; if(read(input,buffer_header,4) > 0) image_width = bytesToInt(buffer_header); printf("%d\n",errno); What's happening is that the condition...

Storing columns on disk and reading rows

c++,file,matrix,io
So I have a C++ code that finds the inverse of a square matrix. The inverse is full and it would be bad to keep it all in memory because I am working with hundreds of thousands of columns. My code generates the columns one by one. After finding the...

In ubuntu unable to write file in specified directory using java

java,ubuntu,io
While trying to write file in specified directory i am getting exception. Java code :- public void jsonToYaml(JSONObject json, String studioName) throws JSONException, org.codehaus.jettison.json.JSONException, IOException { Yaml.dump(Yaml.dump(JsonToMap.jsonToMap(json)), new File("config.yml")); BufferedReader br = new BufferedReader(new FileReader("config.yml")); String line; studioName = studioName.toLowerCase(); File writeFile = new File("sudo /var/iprotecs/idns2.0","" + studioName + ".yaml");...

Maximum size/offset of streamed File using Ada.Streams.Stream_IO.Read

io,filestream,ada,gnat
I try to read specific blocks of Data (around 4096 bytes) from a (possibly) huge file. Using Ada.Streams.Stream_IO.Read() with the GNAT compiler, what would be the maximum offset that I could use? That is, if I wanted to read the last 4 kilobytes of the file, using type Block_Array is...

2- vs 3-argument open with '-'

perl,io,stdin
The following opens STDIN and then echos user input: open my $in, '-'; print "You said: $_" while(<$in>); However, the following snippet dies because it can't find any file called '-': open my $in, '<', '-'; # dies print "You said: $_" while(<$in>); Why does the two-argument open work for...

function to delete folders older than 10 days in vb

vb.net,io
I want to create a function which should delete all subfolders of a folder which are 10 days older. Shell script delete folders older than n days I want show all the folder and count how much old and delete if it is 10 days old. enter code here Private...

javscript readstream line by line

javascript,file,csv,io
I'm trying to read in a CSV file line by line and add each line to an array, my code so far is: var csvFile = 'Domain.csv'; var fs = require('fs'); var readableStream = fs.createReadStream(csvFile); var data = ''; readableStream.on('data', function(chunk) { var temp = ''; temp = chunk; global.qArray.push(temp);...

why char* why not bool* can be used in write function in c++ file I/O

c++,file,io,typecasting-operator
In this statement why cast x to char* and not to bool*- out.write( (char*)&(x), sizeof(double) ); ...

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...

How does C distinguish between a byte long character and a 2 byte long character?

c,linux,bash,io,kernel
I have this sample code: #include <fcntl.h> #include <stdio.h> #include <unistd.h> int main(void){ printf("%li\n",sizeof(char)); char mytext[20]; read(1,mytext,3); printf("%s",mytext); return 0; } First run: [email protected]:~$ ./a.out 1 pp pp [email protected]:~$ Well I think this is all expected as p is 1 byte long character defined in ASCII and I am reading...

Convert InputStream into Stream given a Charset

java,io,stream,java-8,java-stream
I want to convert an InputStream is into a Stream<String> stream given a Charset cs in such a way that stream consists of the lines of is. Furthermore a line of is should not be read immediately but only in case stream needs it.

Rust: Lifetime of String from file [duplicate]

file,io,rust
This question already has an answer here: Return local String as slice 1 answer I'm trying to read in some external GLSL code into Rust. The reading works properly, but I run into a lifetime issue in the final expression (in the Ok(_) branch) error: s does not live...

How to make an array loaded from netCDF (.nc) writeable?

python,arrays,numpy,io,netcdf
I am loading a few variables from a netcdf (.nc) file using python scipy.io.netcdf module. In the file that I am loading them from, missing data have a filler value of 99999, which I want to change to np.nan from numpy. Once I have imported a variable and assigned it...

Why is it slower to print directly to console/terminal than redirecting?

linux,io,terminal
Why does it take significantly more time to print multiple lines to the terminal rather than redirecting it to a file which seems to be almost instant ?

Mixing Java NIO with IO input streams read operation

java,sockets,io,nio
I need to use NIO to allow the server side to support timeout on write operations, but handling reading operations on the socket channels complicates my program. I was wondering if it's possible to write to the sockets using NIO but to read using regular IO, something like ((SocketChannel) selectedKey.channel()).socket().getInputStream().read(buffer)...

FileNotFoundException While trying to copy the file from one directory to another

c#,.net,io,filenotfoundexception
I have some files (.txt, word, excel files) in "C:\ABC\Temp" and I want to move all the .txt files into "C:\ABC\Text", but I'm getting a FileNotFoundException. Please find attached code. static void Main() { string sp = @"C:/ABC/Temp"; string dp = @"C:/ABC/TextFiles"; string[] fileList=Directory.GetFiles(sp); foreach(string file in fileList) { if...

How to call Fortran routine with unit number argument from C

c,io,fortran,shared-libraries,abi
If I have a Fortran subroutine which takes a Fortran IO Unit as one of its parameters (for printing debug information to), and this function is compiled into a shared library, how do I correctly call this function from C? ! An example subroutine that I want to call from...

Can't write to a Handle

haskell,io,handle
I'm writing a chat server in Haskell. My executable has the following code: data Client = Client {idx :: Int, hClient :: Handle} deriving (Show, Eq) tellClient :: String -> Client -> IO () tellClient = flip $ hPutStrLn . hClient askClient :: Client -> IO (String) askClient = hGetLine...

monitor log4j behaviour under load

logging,concurrency,io,log4j
I want to test my J2EE application under high load of sessions accessing different pages. This web application uses Log4J to log bunch of errors,warnings and infos. I want to test what is the side effect of this load on writing log files, especially concurrent I/O writing actions. I found...

Getting input in java

java,io
I wanna to get input from console while it has input. Now my code is this: Scanner scan = new Scanner(System.in); String word = "s"; while (word.length() > 0) { word = scan.nextLine(); if (!word.equals("")) t.addWord(word); } but in some cases it gives me no such element exception . I...

Python csv seek() not working

python,csv,io
Hi I am trying to read a csv file using the following code. I want to read from n th line to m th line of the csv file provided. As a example I want to start reading from 10th line to 100 line and after that start from 500th...

Python will Sometimes Not Read in Entire File

python,io,enumeration
I have python 2.7 program used on a unix server that reads in an ASCII file with two types of information and processes that information. I have put this process into a function that essentially does: def read_info() f = open(file_name, 'rb') f_enumerator = enumerate(f, start=1) for i, line in...

Can someone explain mdict in python (scipy.io), for example in scipy.io.savemat()?

python,matlab,io,scipy
I have been working on loading some files in python, and then once the files are loaded I want to export them into a .mat file and do the rest of the processing in MATLAB. I understand that I can do this with: import scipy.io as sio # load some...

Clone a file and modify it

c#,file,io
I'm new to C# and I just want to use it for a project. I'd like to code a program that read some file and clone them line by line. If a line is a trigger, it would call a function which will add some other lines instad of the...

read file from assets android

android,io
I'm trying to build a card viewer in android for a trading card game. My plan was to use an arraylist to populate the cards into the database. I would read in all values from file and would be displayed via listview. My listview code and arraylist code is fine...

How fast can we make a specific tr?

c,performance,io
I had to replace all the null bytes in a file with another character (I arbitrarily chose @), and was pretty surprised that tr '\00' '@' was about 1/4 the speed of gzip: $ pv < lawl | gzip > /dev/null ^C13MiB 0:00:04 [28.5MiB/s] [====> ] 17% ETA 0:00:18 $...

IO reading (java)

java,io
if i have a loop like so: while(st.hasMoreTokens() ) { array[i] = st.nextToken(); array[(i+1)] = st.nextToken(); i++; } will array[i] and array[i+1] end up having the same word or will it put one word in array[i] and the next word in array[i+1]? i'm trying to read in 2 words at...

Fortran runtime error “bad integer for item 11 in list input”

io,fortran
I receive the runtime error "bad integer for item 11 in list input" referencing the following line of code. read(2,*)a,b,c,d,e,f,g,h,theta1,phi1,k,l,m,n,o, $ p,theta2,phi2,s,theta3,phi3, $ r1,x1,y1,r2,x2,y2,r3,x3,y3,z1,z2,z3 The line its reading from is 1 255.11211 0.2876 165.11404 90 4 8 0.19173 90 165.11404 0.09587 90 345.11404 4 4 0.0764 89.99915 -64.51149 0.11131 90.0015...

how to reattach sys.stdout to console window in python?

python,io,stdout,stringio,redirectstandardoutput
My python 3 doodling went like this: import io, sys sys.stdout = io.StringIO() # no more responses to python terminal funnily enough My question is how to reattach so when I pass in 1+1 for example it'll return with 2 to the console? This is in the python interpreter on...

How to find condition that start char in UTF-8 file is read, using FileStream and StreamReader?

c#-4.0,utf-8,io,stream
In C# .NET 4.0 (really 4.5.2), my code reads a UTF-8 file. FileStream fstream = new FileStream(path, FileMode.Open); BufferedStream stream = new BufferedStream(fstream); using (StreamReader reader = new StreamReader(stream, new UTF8Encoding())) { int i; while((i = reader.Read()) > -1) { //a guess at a condition that is true I.F.F. reader...

How do I do user inputs on the same line in Lua?

input,io,lua
Here is my code: while true do opr = io.read() txt = io.read() if opr == "print" then print(txt) else print("wat") end end What I'm trying to do is make it where you type print and then whatever you want like this: print text And it'll print text but I...

Why is my text file always empty?

java,file,io
I have created a game that saves your high score in a text file called highscores.txt. When I open the game, the correct high score is displayed. But when I open the text file, it is always empty. Why is this? Here is my code for writing and reading the...

Haskell: Clear file contents using an open handle

haskell,io,handle
In Haskell, how can one clear a file's contents when you already have an open file handle and do not wish to close it? Is there some easy way that isn't apparent to me from the System.IO API? In a less restrictive situation, the easiest way to clear a file's...

Unidentified symbol

java,io,symbol
Given the following: import java.io.*; public class WriteRead { public void writeToFile(String filename) throws IOException { FileWriter fw = new FileWriter(filename); fw.write("testing"); fw.close(); } public String readFromFile(String filename) throws IOException { String str = ""; int characterInt = 0; FileReader fr = new FileReader(filename); while (characterInt != -1) { characterInt...

File I/O error FileNotFoundException

java,io,backtracking
The following is the java code. I am trying to get the arrays from the problem1.txt and save it into the arraylist. import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; class CSP { public int nMeetings; public static int nEmployees; public int nTimeSlots; public...

the logic behind the diffrerence between fileInputStream and Scanner classes

java,io,java.util.scanner,fileinputstream
I'm trying to understand the difference between Scanner.nextByte() and FileInputStream.read(). I read similar topics, but I didn't find the answer of my question. A similar question is asked in the topic : Scanner vs FileInputStream Let me say what I understand : Say that a .txt file includes 1 Then,...

Pylint on StringIO or buffered text

python,io,pylint
I need to analyze some code generated "magically" in a function. The example I'm using is very simple. Here is what I intend to do: from pylint import epylint from StringIO import StringIO source = StringIO() source.write('def test():\n') source.write(' b = 5\n') source.write(' return\n') source.seek(0) epylint.py_run(source) The result I get:...

Using pygame to play a MIDI file from stream

python,io,pygame,midi,bytesio
What I want to do is the following: Create a MIDI file, but only in memory, and feed it into pygame.mixer.music.load(). Here is what I've been trying (I'm using MidiFile from here): import pygame.mixer import MidiFile3 import io pygame.mixer.init() midi = MidiFile3.MIDIFile(1) # midi file with one track midi.addTrackName(0,0,"Track 1")...

Getting input java

java,io
same as thisquestion I want to get input from user while he/she give me strings. but the difference is that now before I get strings , I must get 26 numbers. so this code works wrong in getting myStrings. what should I do? Wrong code: for (int i = 97;...

Mapping with IO actions in Haskell

list,haskell,io
I have a function that takes two filenames, and reads the contents of those two files into Strings, and then returns if they match or not. Here's the function: f :: String -> String -> IO Bool f fileName1 fileName2 = do str1 <- readFile fileName1 str2 <- readFile fileName2...

Unique words save to text file as a word per line

python,file,python-3.x,io,text-files
[using Python 3.3.3] I'm trying to analyse text files, clean them up, print the amount of unique words, then try to save the unique words list to a text file, one word per line with the amount of times each unique word appears in the cleaned up list of words....

Loading resource files within a jar

java,jar,io,loading
What's the best way to load resources (Sounds, images, xml data), that also works from inside a distributed jar file? I need to load some sounds, images, and xml data, for use in my program. Using AudioInputStream ais = AudioSystem.getAudioInputStream(new File("~/src/com/example/package/name/assets/TestSound.wav")); does not work in the jar, for obvious reasons,...

Java 7 - Stream data through class hierarchy

java,performance,io,stream
I am trying to write some sort of class hierarchy, more specifically, an execution hierarchy. Data should be passed down the hierarchy through each element whilst being modified during the process. Concurrency is not an issue, although it is part of a multithreaded program. To clarify: I do not want...

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?

Issue reading and saving lines from .txt file in Java

java,arraylist,io
Objective & Issue Objective of the task I am trying to accomplish is to locate and read a text file from a provided path then copy each line of the text file into a ArrayList<String>. This "ApplicationFileReader" object is created in some control class by calling the constructor which takes...

C++ not reading anything from files

c++,io
I seem to be having a problem reading files. I am using Visual Studio Community 2013 and it will do everything but reading of files. I have checked to make sure the file being read and written is in the same directory. The following code is where I believe the...

input errors : split part of one entery

c++,input,io
i am doing some practice on standard I/O i have a complex class . my class has overloaded insertion and extraction operators ,the input should of the form : x + yi(e.g 10 + 9i) i have to determine if input is valid or not . there is the problem...

Firefox OS - save file in the app directory

javascript,audio,io,firefox-os,howler.js
I am currently developing an audio editing application for firefox OS (github). That uses, for playback, Howler JS (link). On Firefox OS, I can easily play audio files which are within the application folder (does not matter where) only by passing an URL to Howler, but, if I want to...

How to prevent a race condition when multiple processes attempt to write to and then read from a file at the same time

python,io,race-condition,python-import,python-os
I have the following code (simplified for clarity): import os import errno import imp lib_dir = os.path.expanduser('~/.brian/cython_extensions') module_name = '_cython_magic_5' module_path = os.path.join(lib_dir, module_name + '.so') code = 'some code' have_module = os.path.isfile(module_path) if not have_module: pyx_file = os.path.join(lib_dir, module_name + '.pyx') # THIS IS WHERE EACH PROCESS TRIES TO...

Is there a simple way to tell if a StackTraceElement is not from your source code?

java,io
Here's an example app, throwing an error at Foo.main(): public class Foo { public static void main(String args[]) { try { throw new RuntimeException(); } catch (Exception e) { for (StackTraceElement elem : e.getStackTrace()) System.out.println(elem); System.exit(-1); } } } Here's the output: Foo.main(Foo.java:5) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)...

C++ reading a file into a struct

c++,struct,io,fstream
Using fstreams I have a file opened that contains numerous lines. Each contiguos set of 4 lines are such that: the first line is an int, the second and third are strings and fourth is a double. This sequence continues till EOF. I'm attempting to load these lines into a...

User Input Java

java,input,io
I am building an application in Java (using NetBeans) that accepts user input through the console and prints out a statement using their name (given in user input). The following is the code: package amazingpets; import java.io.Console; public class AmazingPets { /** * @param args the command line arguments */...

Using allocatable/assumed-size arrays with namelist read write

io,fortran,intel-fortran,fortran2003
I am using VS2012 and Intel Visual Fortran 2015. According to https://software.intel.com/en-us/forums/topic/269585, it is now allowed to use allocatable and assumed-size arrays with namelist read and write; however, I am still getting the error "A namelist-group-object must not be an assumed-size array". example code: subroutine writeGrid(fname, grid) character*(*) :: fname...

Why does grep give “Binary file (standard input) matches”?

c,file,api,io,pipe
#include <stdio.h> int main() { FILE* cmd = popen("grep Hello", "w"); fwrite("Hello\n", 6, 6, cmd); fwrite("Hillo\n", 6, 6, cmd); fwrite("Hello\n", 6, 6, cmd); pclose(cmd); } The program above outputs: Binary file (standard input) matches Why does grep give the message, and how to fix it?...

Creating objects with data from file

java,file,io,hashmap
I’ve got a text file with data for my application and I want to create objects with that data. Every line in the text file is one object in format: <name> <posX> <posY> <posY> <velX> <velY> <velZ> <mass> <radius>. line is a String with one line from that file. To...

Modern C++ idiom for allocating / deallocating an I/O buffer

c++,memory-management,io
For I/O work, I need to read N bytes into a buffer. N is known at run time (not compile time). The buffer size will never change. The buffer is passed to other routines to compress, encrypt, etc: it's just a sequence of bytes, nothing higher than that. In C,...

How would I go about searching for a string of words across multiple lines

java,parsing,input,io,bufferedreader
This is a homework assignment I am working on which required me to read data from a file and the parse through it finding the line number and starting index of certain key phrases or names. The file is being hosted online so I've decided to use the URL class...