file-read

Ruby Reads Different File Sizes for Line Reads

I need to do something where the file sizes are crucial. This is producing strange results filename = "testThis.txt" total_chars = 0 file = File.new(filename, "r") file_for_writing = nil while (line = file.gets) total_chars += line.length end puts "original size #{File.size(filename)}" puts "Totals #{total_chars}" like this origina...

Why does my Perl if condition always evaluate to true?

In Perl, I need to read a .conf file that contains either a 0 or a 1. If the value is one, I need to execute whatever is in the if statement. Here is what I have now: open(CONF, "/var/web/onhit.conf"); if(<CONF>) { print "Hello World!"; } close(CONF); The contents of the if statement always evaluate, even if the .conf file contains...

How to read lines from a text file one by one with Power Point VBA code?

This code will read a line from a text file: set file = CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\number.txt", 1) text = file.ReadLine MsgBox text How can I make it read repeatedly one line after another from the same file? I guess, I should use a loop here, right? I need it to read the first line from the file at th...

File-read into div through ajax. I'm missing something small I think!

Hello. I'm doing something very simple, and yet it's not working.. maybe I'm missing something. I need to read a text file, through ajax, and into a div. I can easily write to the file through ajax, but not read. Here is what I have: function ajaxLoader(url) { if(document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXOb...

Reading PDF file to get tabular data in structured format,

I have to read a pdf file which contains a table with several columns. Using iTextSharp I am able to read the file but I get bunch of non-formatted text. I am not able to structure the data so that I can insert into a database. Any suggestions? ...

C-programming ftell fseek fread, read size of a file

I have a file. I read the size of file. Then I loop reading two bytes at a time until I get to the end of the file. After every read operation I increment the current position by 2, however the position does not get incremented after I get to half the size of the file, the fread operation will read 0 bytes. the program reads the file si...

With Perl, how do I read records from a file with two possible record separators?

Here is what I am trying to do: I want to read a text file into an array of strings. I want the string to terminate when the file reads in a certain character (mainly ; or |). For example, the following text Would you; please hand me| my coat? would be put away like this: $string[0] = 'Would you;'; $string[1] = ' please hand me...

How to read values from file. tokenizer

I have a file in which each line contains two numbers. The problem is that the two number are separated by a space, but the space can be any number of blank spaces. either one, two, or more. I want to read the line and store each of the numbers in a variable, but I'm not sure how to tokenize it. i.e 1 5 3 2 5 6 3 4 83 54 23 ...

Java FileInputStream ObjectInputStream reaches end of file EOF

I am trying to read the number of line in a binary file using readObject, but I get IOException EOF. Am I doing this the right way? FileInputStream istream = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(istream); /** calculate number of items **/ int line_count = 0; while( (String)ois...

Read multiple strings from a file C++

Hi I need to read different values stored in a file one by one. So I was thinking I can use ifstream to open the file, but since the file is set up in such a way that a line might contain three numbers, and the other line one number or two numbers I'm not sure how to read each number one by one. I was thinking of using stringstream but...

Read a file until a character in C

Say I have a file with the format: key1/value1 key2/value2 key3/value3 .... Say I have an array to hold these values: char *data[10][10] How would I read this file and get key1, key2, and key3 into data[0][0], data[1][0], and data[2][0]. Then put value1, value2, and value3 into data[0][1], data[2][1], and data[3][1]. So actually I ...

C++ problem with string stream istringstream

I am reading a file in the following format 1001 16000 300 12.50 2002 24000 360 10.50 3003 30000 300 9.50 where the items are: loan id, principal, months, interest rate. I'm not sure what it is that I am doing wrong with my input string stream, but I am not reading the values correctly because only the ...

C# acting weird when reading in values from a file to an array

This is the structure of my file: 1111111111111111111111111 2222222222222222222222222 3333333333333333333333333 4444444444444444444444444 5555555555555555555555555 6666666666666666666666666 7777777777777777777777777 8888888888888888888888888 9999999999999999999999999 0000000000000000000000000 0000000000000000000000000 000000000000000000...

Delphi: how to efficently read a big binary file, converting it to hexadecimal for passing it as a varbinary(max) parameter?

I need to convert a binary file (a zip file) into hexadecimal representation, to then send it to sql-server as a varbinary(max) function parameter. A full example (using a very small file!) is: 1) my file contains the following bits 0000111100001111 2) I need a procedure to QUICKLY convert it to 0F0F 3) I will call a sql server funct...

Printing char pointer in C - I keep getting bad formatting

I am reading a line from a file containing the names of people, first line contains names of males, and seconds line contains names of females. Then I want to store these names in two arrays, one for males, one for females, however when I print them I get weird things. I'm not sure if I am not reading them correctly, or printing them inc...

Working with files and utf8 in PHP

This is driving me crazy. Lets say I have a file called foo.txt encoded in utf8: aoeu qjkx ñpyf And I want to get an array that contains all the lines in that file (one line per index) that have the letters aoeuñpyf, and only the lines with these letters. I wrote the following code (also encoded as utf8): $allowed_letters=array("...

reading a file using java scanner

One of the lines in a java file I'm trying to understand is as below. return new Scanner(file).useDelimiter("\\Z").next(); The file is expected to return upto "The end of the input but for the final terminator, if any" as per java.util.regex.Pattern documentation. But what happens is it returns only the first 1024 characters from the...