Reading single line of the text file
I use the following code to read a .txt file
private String readTextFile (String fName) {}
String result = null;
FileConnection fconn = null;
DataInputStream is = null;
try {}
fconn = (FileConnection) Connector.open (fName, Connector.READ);
is = fconn.openDataInputStream ();
Byte [] = IOUtilities.streamToBytes (is) data;
result = new String (data);
} catch (IOException e) {}
System.out.println (e.getMessage ());
} {Finally
try {}
If (null! = is)
is. Close();
If (null! = fconn)
fconn. Close();
} catch (IOException e) {}
System.out.println (e.getMessage ());
}
}
return the result;
}
I want to print a single line instead of the file around so I read that I need to store the contents of the file into an array and then get the index of the line. Problem is that I couldn't find any information on how to do it. Can someone give me a shot. Thanks in advance.
This isn't a problem with encoding. You just need to do a little extra accounting and adjust start and end indices to remove these characters. To treat the "\r\n" of line termination style, you can maintain a flag (initially false) to indicate that the previous line ended with a \r; If a line begins with \n, it should be treated as the end of a line (empty) if the flag is true (in which case it should be ignored).
If you want to extract all lines (not just the first), then it may be easier to do this accounting while avoiding a separate function. Something like this (untested):
// read the file into a byte array 'data'; then: Vector lines = new Vector(); boolean endCR = false; int start = 0; for (i = start; i < data.length; ++i) { if (data[i] = 0xD) { lines.addElement(new String(data, start, i - start)); endCR = true; start = i + 1; } else if (data[i] = 0xA) { if (endCR && i == start) { start++; endCR = false; } else { lines.addElement(new String(data, start, i - start)); start = i + 1; } endCR = false; } } String[] results = new String[lines.size()]; lines.copyInto(results);
Tags: BlackBerry Developers
Similar Questions
-
Add data at the end of a specific line in the text file
Hello
I'm trying to add data at the end of the last 4 lines of the text file attached with the ' table to add. 4 rows (422.5800 entry), I would add the first entry of the 'Array to add' entry, on the 5th line to add the second entry of the 'Add picture' and so on. How can I do this?
Any help will be appreciated.
Sincerely,.
hiNi.
After re-reading your post, I think that's what you really want to start adding after the first 4 rows.
-
Need help: UTL_FILE read and write in the text file
Hello, I'm on version 11 GR 2 by using the UTL_FILE function to read a text file and then write the lines where it starts with the word "foo" and put an end to my writing in the text file where the line with the word "ZEN". Now I have several lines that begin with 'foo' and 'ZEN' allow a paragraph, and in this paragraph, there is a line that begins with "DE4.2". Therefore,.
I need to write all of the paragraphs that include the "DE4.2" line in their beginning and end of lines 'foo' and 'ZEN '.
FOR EXAMPLE:
FOO/234E53LLID
IT'S MY SECOND LINE
IT'S MY THIRD LINE
DE4.2 IT OF MY FOURTH LINE
IT'S MY FIFTH LINE
ZEN/DING3434343
FOO/234E53LLID
IT'S MY SECOND LINE
IT'S MY THIRD LINE
IT'S MY FIFTH LINE
ZEN/DING3434343
I'm only interested in writing the first paragraph tha includes line DE4.2 in one of the paragraph of lines not the second ther that does not include the "DE4.2".
Here is my code so far:
CREATE OR REPLACE PROCEDURE my_app2 IS
Utl_file.file_type INFILE;
outfile utl_file.file_type;
buffer VARCHAR2 (30000);
b_paragraph_started BOOLEAN: = FALSE; -flag to indicate which required paragraph is started
BEGIN
-Open a file to read
INFILE: = utl_file.fopen ('TEST_DIR', 'mytst.txt', 'r');
-Opens a file for writing
outfile: = utl_file.fopen ('TEST_DIR', "Out.txt", "w");
-Check the file is open
IF utl_file.is_open (infile)
THEN
-lines in the file in loop
LOOP
BEGIN
UTL_FILE.get_line (infile, buffer);
APPLICATION STARTING POINT-
Buffer IF LIKE 'foo %' THEN
b_paragraph_started: = TRUE;
END IF;
-SEARCH FOR GRADS APPS
IF b_paragraph_started AND buffering LIKE '% 4% ' THEN
UTL_FILE.put_line (outfile, buffer, FALSE);
END IF;
-REQUEST FOR ENDPOINT
Buffer IF LIKE '% ZEN' THEN
b_paragraph_started: = FALSE;
END IF;
UTL_FILE.fflush (outfile);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
END LOOP;
END IF;
UTL_FILE.fclose (INFILE);
UTL_FILE.fclose (outfile);
EXCEPTION
WHILE OTHERS THEN
raise_application_error ("-20099, ' UTL_FILE unknown error");
END my_app2;
/
When I run this code I get only one line: DE4.2 it ME LACK THE WHOLE PARAGRAPH
PLEASE ADVISE...I agree with reservations of Justin on the length of a "paragraph" and the number of users that are running at the same time, so here is a version without the collections.
CREATE or replace PROCEDURE my_app2 IS infile utl_file.file_type; outfile utl_file.file_type; buffer VARCHAR2(30000); b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started b_toprint BOOLEAN := FALSE; l_para_start pls_integer; -- start of "paragraph" BEGIN infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r'); outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w'); LOOP BEGIN utl_file.get_line(infile, buffer); IF buffer LIKE 'FOO%' THEN b_paragraph_started := TRUE; l_para_start := UTL_FILE.FGETPOS(infile) - (length(buffer) + 1); END IF; IF b_paragraph_started and buffer like '%DE4%' THEN b_toprint := TRUE; END IF; If buffer like 'ZEN%' THEN IF b_toprint THEN UTL_FILE.FSEEK(infile, l_para_start); utl_file.get_line(infile, buffer); while buffer not like 'ZEN%' loop utl_file.put_line(outfile,buffer, FALSE); utl_file.get_line(infile, buffer); end loop; utl_file.put_line(outfile,buffer, FALSE); end if; b_paragraph_started := FALSE; b_toprint := false; utl_file.fflush(outfile); end if; EXCEPTION WHEN no_data_found THEN EXIT; END; END LOOP; utl_file.fclose(infile); utl_file.fclose(outfile); END my_app2;
Test:
SQL> !cat mytst.txt FOO/234E53LLID THIS IS MY SECOND LINE THIS IS MY THIRD LINE DE4.2 THIS IS MY FOURTH LINE THIS IS MY FIFTH LINE ZEN/DING3434343 FOO/234E53LLID THIS IS MY SECOND LINE THIS IS MY THIRD LINE THIS IS MY FIFTH LINE ZEN/DING3434343 FOO/234E53LLID again THIS IS MY second SECOND LINE THIS IS MY second THIRD LINE DE4.2 THIS IS MY second FOURTH LINE THIS IS MY second FIFTH LINE ZEN/DING3434343 again SQL> exec my_app2; PL/SQL procedure successfully completed. SQL> !cat out.txt FOO/234E53LLID THIS IS MY SECOND LINE THIS IS MY THIRD LINE DE4.2 THIS IS MY FOURTH LINE THIS IS MY FIFTH LINE ZEN/DING3434343 FOO/234E53LLID again THIS IS MY second SECOND LINE THIS IS MY second THIRD LINE DE4.2 THIS IS MY second FOURTH LINE THIS IS MY second FIFTH LINE ZEN/DING3434343 again
You may need to change the length (buffer) + 1 depending on your platform and if you want a blank line s NLE out paragraphs, add another call to put_line after that outside of the loop in the fi l_toprint block.
John
-
Problem with end of line in the text file.
Using LabVIEW 2010 on W7 64 bit in the USA.
I have an application in which I write in a text file. I use the function "Write to a text file" to write the text and "Reading a text file" function to read again. My problem is with the end of line character. The text that I write is a long chain, not an array of strings. While building this chain, I insert the constant EOL of the palette of channels function to indicate that a new line is planned. My tests showed this EOL constant values of consecutive bytes 13 and 10. After writing all the text in a file, I can open the file with Notepad, or Word, or something else, and it is displayed correctly. When I read he returned with the function of text file reading, I'm trying to parse the string by searching for the same constant EOL, but it does not work. A closer examination of the extracted string from the file reveals that the value of end of LIFE has changed for only 10. The location of the byte to 13 disappeared. I know there is a note on the writing of the function of text file add/change the EOL characters, which are the default values of the system, but the note specific tables. I manually put the value in the string. Does anyone know why this happens and how to fix it?
Thank you.
The help of reading from text file function
The function converts all characters in end of line break characters online platform, dependent unless you right-click the function and remove the check mark next to the menu item Convert EOL .
Right-click your reading and uncheck the EOL conversion. I recommend to do the same thing to your writing to text file feature.
-
How to concatenate strings with the lines of a text file
HelloI tried concatenate strings with the lines of a text file, but something is wrong with my code and I belive is the agruments I use in the cycle for. If anyone can help me I will appreciate it very much.My code is:[code]@echo offthe value "input=C:\Users\123\Desktop\List.txt".for /f "usebackq tokens = *" % in (' input % ') do)the value 'str1 = C:\some directory\ ".the value ' str2 = %% ~ F '.the value "str3 = .pdf".the value "str4 = str1% str2% str3%.echo.%STR4%) [/ code]and the text file is something like:121122 [code]122233123344124455 [/ code]But I get only one wrong answer and I have to run it like 3 times to get a real result and it is a mistake, the first two are empty spaces and gives the third one as the last line of the text file but repeated n times, where n is the number of lines in the text file.Result:[code] C:\Users\123\Desktop>concatenate.batC:\Users\123\Desktop>concatenate.batC:\Users\123\Desktop>concatenate.batC:\some directory\124455.pdfC:\some directory\124455.pdfC:\some directory\124455.pdfC:\some directory\124455.pdfC:\some directory\124455.pdfC:\Users\123\Desktop>[/code]So if anyone has an idea about what is wrong please let me know.Concerning-Victor-Hi Victor,
This forum is dedicated to the support of the Office of consumer Windows (fonts, colors, personal settings). Since your question is about programming and usually outside the context of most of the customers, I suggest you post your question in the forums as http://msdn.microsoft.com - the Microsoft network to users will be more adapted to help you in your quest. -
testimonial widget that reads the text file
Is there someone who makes a testimonial widget that can read a text file? I am considering this is a block for customer testimonials that can read a file of say 50 different clients we wil cut and paste from various places, so that there is always a fresh review illustrated.
Themes of Muse has some text widgets: one as a ticker-tape driveand displays a (small) number of citations. But none will allow you to modify a file of text outside the Muse of let's say 50 paragraphs and read on the page, one by one, in order.
There are a lot of scripts to do exactly what you want, like this: alternating Message text box . JavaScriptSource, and many others, just Google: "alternating rotation script of text message". But are you able to manage scripts and HTML codes in Muse ? Maybe some useful script Wizard can cook a place for you or modify an existing one, provide you a text template file and help hair and be implemented in Muse page.
Don't let them not to edit your output !
Ask them to help you with a method to ensure within the Muse:
1. adds a style and script in the header of page (see Page Properties)
2 Insert the HTML code on the page (under the object menu)
3 attach the text file on the site (hyperlink, link to the file)
So, you can change the text file and download all changes with Muse.
Hope this helps?
-
Use the lines of a text file as input to an SQL command
Hello
I have a text file containing the lines...
123
1234
I would like to use as input for a SQL command running in a script. ie
Update flag set < table > = 'Y' where job = < the text file lines >;
Any help much appreciated.
See you soon
External table will do.
For reference...
CREATE TABLE Hold'em (SEQ_NUM NUMBER (10));
insertion in hold select SEQ_NUM in task where proc like '% PROC;
update set hold_flag = task ' ' where in SEQ_NUM (select hold SEQ_NUM);
-
Adobe Reader highlight tool is more full of text, simply create a line around the text
The highlight in Adobe reader tool no longer works as before. Instead of filling the text, as it is used, the tool creates just a line around the text. This makes it much harder to identify strengths.
I am running Win 8 and using Adobe Reader XI version 11.0.09.
I have attached a screenshot to illustrate. The way the tool used to work, they testify as I want it, highlight all the text in the document. As it is it currently works, is shown on the first line of the text, where a part of the text was highlighted with the tool as it works now. I have just created a yellow line around the text.
I checked how the highlight settings are both the former highlight text and the new text, and they look identical. Percentage of the color settings and opacity are the same.
Very frustrated. Any help appreciated.
Try to run a repair from Acrobat (via the Help menu) installation.
-
AprΦs the dΘmarrage of battery empty, a text file named Guadeloupe (which I didn't create) with a single (visible) line of the text with some strange characters is open along with other programs that start at startup. Now, I tried to locate the source of this file without success - it's as if the file does not exist. I did not always have this problem (or event) arrive, and I didn't know of any other cases when searching online.
Any help or information will be greatly appreciated.
I'm on an Early 2011 Macbook Pro 13 inches, 2.3 GHz, 8 GB ram i5 upgraded, under OS X 10.10.5.
One of your connection objects may be causing the problem. Please select the login items tab in the users pane and groups of system preferences. Remove all items that you do not recognize. If you don't know which ones to delete, double-click on each to test.
If a connection item is dimmed and cannot be deleted, click on the padlock icon in the lower left corner of the window and enter your login password when you are prompted. Then try again.
To avoid confusion, please note that checking or unchecking the box next to a point of idle connection not she. You must remove the item from the list.
-
Odd number of columns in the text file
Hello everyone
From an Excel (.xls) file, I saved (tabs-delimited text) file and open in Labview. The file has only 2 columns (apparently), but my VI says he has 12! I tried to find any character 'lost' in the file but it's all in the first two columns.
However, if I open the .xls file, save the text file delimited tab, open this tab delimited text file using excel, hit save and then open in my VI, the VI will tell me that the file has only 2 columns. Strange.
Enclosed please find my VI (I tried two different methods to load the file and got the same results).
Thank you
Dan07
Around this line, you will notice a bunch of tabs:
240.4926373\t507.1851226\t\t\t\t...
Edit: I would like to clean up the source, but if you're stuck here is a way to clean:
-
Can all help with VI to get data (HEX) serial number and write in the text file
Hello I am struggling with this problem for 2 months... They get help from different I thought I solved the problem, but of no use yet I stand on zero
Problem: I need to get data on USB high speed HEXAGON shaped (coming in hexadecimal and be stored in the text file to the hexadecimal format as each hexadecimal value online different I'll also to attach the file)
Get us ASCII on series or VISA read but when trying to convert to hex as shown in text file making it slower to deal with code, I know that my VI will have to improve more... I'm waiting for suggestions
Need urgent help...
Thanks in advance
Hi Ali Afzal,.
I think that the attached example can work for you. If not, then try the solution with sending the data to a parallel running the loop and store it there.
Mike
-
Playback/record to the text files using HTML5 as a basis for the code
Hi, I'm new and I did some research and I found a variety of solutions that seemed a little more complicated than I want. I would like someone to direct me to something that could teach me how to do two things.
(1) read the text files (essentially my difficulty is how to interact with the file system of playbook for reading files and how to save text files with output 2).
It is not necessary to try and catch.
Thanks in advance!
Hello ignites,
The following thread contains an example of manipulation of text files and also contains a link to another thread by Tim Windsor where he describes working with other file types:
Let me know if you have any questions.
Erik Oros
BlackBerry Development Advisor
-
How to return to the line in the text field
I created a form with a text field, but by filling out the form, the words don't word wrap, but just go in a single line across the field to text box.
When can I format the text box for the return to the line?
TKS
Under the Options tab of the Properties dialog box, you can set the Multiline field.
-
Dynamic text from the text file problem
Go step by step to get my data from MYSQL/php... for now, I'm stuck and cannt even get it from a text file I do worng!
This is the code I use:
var myLoader:URLLoader = new URLLoader()
myLoader.dataFormat = pouvez
myLoader.load (new URLRequest ("trees.txt"))
myLoader.addEventListener (Event.COMPLETE, onDataLoad)
function onDataLoad(evt:Event) {}
for (var i: uint = 0; i < evt.target.data.cant; i ++) {}
This ["tcname_" + i] .text = evt.target.data ["tcname_" + i]
}
}
My trees.txt file contains the following:
Plum = tcname_0 & tcname_1 = olive
I made this as well:
& tcname_0 = Asian plum & tcname_1 = Amazon lily &
I have already created a few instances of dynamic text from tcname_0 up to tcname_5
I tried with having the text in dynamic text or leave it empt anyway... nothing is read from the text file, what I am doing wrong?
In your trees.text file, you neglected to include the variable of cant, so the loop has an undefined value to life...
Plum = tcname_0 & tcname_1 = olive & cant = 2
-
How to write to several lines in the text element?
I tried to write 2 lines in the text element, however only return one row:
: myqueues.queue: = "Hello" | Chr (10) | ' world ';
It gives me only 'Hello' in the first line and nothing else in the 2nd line.
Are there settings needs to be activated in the property of text element?Try this:
DECLARE v_filename VARCHAR(50); v_handle text_io.file_type; begin v_filename := get_file_name(file_filter=>'All files(*.*)|*.txt|'); if v_filename is null then bell; return; end if; v_handle := text_io.fopen(v_filename, 'r'); go_block ( 'myqueues' ); clear_block; text_io.get_line(v_handle, :myqueues.queue ); next_record; text_io.get_line(v_handle, :myqueues.queue ); next_record; text_io.get_line(v_handle, :myqueues.queue ); next_record; text_io.get_line(v_handle, :myqueues.queue ); first_record; text_io.fclose(v_handle); exception when no_data_found then text_io.fclose(v_handle); end;
Published by: Magoo on 02.10.2009 12:01
Maybe you are looking for
-
Update iOS 9.3.1 can get 'my music' any longer. Ideas?
Update iOS 9.3.1 can get 'my music' any longer. Ideas?
-
My updated iphone to date, Req'd new pw, don't let me in.
My iPhone updated, new required password, went online, set up the new pw, phone will not let me.
-
Satellite A40-231: SD-R6112 will not read the DVDs I burned
I finally got my DVD burner to work, but now the drive will not read the DVDs I burned, which, of course, defies the point of having a dvd burner in the first place... When I insert my dvd recently burned, "working" light lights and stays on. Same th
-
Start the display settings button
I turned on my computer the other day and all my settings are gone when I click on the Start button at the bottom left on my desk. I normally have all of my options as we all have, but I have now. The problem has something to do with my customization
-
Download help (edited by mod..)
HY, I'm Lucas and I need help with "Adobe Premiere Pro". When I download it, don't have the ability to open on "creative cloud." What should I do?