Read contents of a file line by line
I want to code a form such that it reads a text file line by line!
i have found the code that includes the text file in res folder and it reads also the contents!!!
but my problem is that i want it to read one line at a time and next line afterwards at another click!!!
This is the main code bt the problem is i dont want it to read whole file at once..............
I want it to read one line at a time.....
thanks for the help any ways.........
public void commandAction(Command c, Displayable s){
String label = c.getLabel();
if (label.equals("Read")){
String string = file();
if (string != null){
alert = new Alert("Reading", string, null, null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, form);
} else if (label.equals("Exit")){
destroyApp(false);
private String file(){
InputStream is = getClass().getResourceAsStream("help.txt");
StringBuffer sb = new StringBuffer();
try{
int chars, i = 0;
while ((chars = is.read()) != -1){
sb.append((char) chars);
return sb.toString();
}catch (Exception e){}
return null;
}
Similar Messages
-
Oracle Service Bus (OSB) - Reading contents of a file line by line
Hi Guys,
I have picked up a file from a remote location using a proxy service. I then pick this file up from my local location using another proxy service (Protocol: file; Get All Headers: No). Now the problem is that I would like to read each and every line contained in this file, that I have picked up from my local folder. After having read the line, I would like to route each line to a web service.
Can somebody who knows their way around the OSB help?
Thanks,
Ophola..Hi Hisaak,
Here is the scenario:
1. I have created a MFL resource that is going to tranform the file into xml.
2. I have added a Request Pipeline, with 2 stages (stage1 for the transformation, stage2 for looping through the elements in the new generated xml object), to my Proxy Service (that picks up the file).
I added and 'If..then..' condition to stage 1. As I have previously mentioned, I want to perform my transformation at this level. So I added an 'action' -> 'message processing' -> MFL Transform. The file seems not to be found, it gets lost somewhere. The problem that I have now is to get the file name from the proxy service request. I have used the following xquery: $inbound/ctx:transport/ctx:request/tp:headers/file:fileName . I think this is wrong as I always get a PipelineException: Binary to XML mfl transformation failed for the MFL Resource "abcde" : Input to non-xml to xml mfl transformation is invalid. On other forum posts they suggest that if you wanna get the filename you have to use the $inbound structure.
Do you have any suggestions?
Thanks,
O.. -
How to read the whole text file lines using FTP adapter
Hi all,
How to read the whole text file lines when error occured middle of the text file reading.
after it is not reading the remaining lines . how to read the whole text file using FTP adapter
pls can you help meYes there is you need to use the uniqueMessageSeparator property. Have a look at the following link for its implementation.
http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_file.htm#CIACDAAC
cheers
James -
Read contents inside pdf file programmatically in SharePoint
I have a SharePoint document library, My Requirement is when user add PDF file on the document library the event receiver fire and read contents inside
pdf file programmatically. After the start workflow according to the result of event receiver.If your question is about handling events in apps for SharePoint, see these links:
http://msdn.microsoft.com/en-us/library/office/jj220048%28v=office.15%29.aspx
http://msdn.microsoft.com/en-us/library/office/jj220051%28v=office.15%29.aspx
If what you need is a way to extract text from the PDF inside the event handler, see this example that uses leadtools.
http://support.leadtools.com/CS/forums/ShowPost.aspx?PostID=43894
You should use PDF text extractor in your Event Handler code -
You can use iTextSharp for reading content
http://www.codeproject.com/Tips/387327/Convert-PDF-file-content-into-string-using-Csharp -
Read from a text file line by line
Hi,
I am new to Labview and I am trying to output a text file line by line. For example if my text file is
START
SETRPM 1000
WAIT 10s
RAMP RPM linear,1000,2000,2 MAF linear,5,7,2
WAIT 5s
RAMP RPM sine,2000,1500,3 MAF sine,7,3,3
END
I want it to output
START
SETRPM 1000
SETMAF 5 ...and so on
I tried modifying this code provided by Altenbach but it is still not working as I want it to. Can anyone direct me toward how I can fix this?
Thank you!
Your program does exactly what you asked it to do. In particular, it will repeat 10 times, at one per second, reading (and storing in String) the (unchanging) data that you bring in on the Shift Register. This data will consist of the first line of the (assumed-)multi-line file you specified.
I suppose your question is "Why is it only showing me one line?" This is where it really pays to "Read the Directions Carefully" (or, in this case, carefully read the Help for Read from Text File).
Bob Schor
P.S. -- I pointed your code at a text file of 7 lines on my PC. When I made a few small changes (including doing away with the silly For loop that shows the same thing over and over) , I got out an array, size 7, containing the lines of text. -
How to read contents of a file version using version url
Hi,
I have a file in a document library say "MyFile.txt". Versioning is enabled and there are three version of it
What i want now is that , by passing the url of version i got from SPFileVersion class, i must be able to read the contents of it.
Can anyone pls help me
Arjun Menon U.KYou can use the following line of code to get the content of a specific version
SPFolder fld = web.Folders["Documents"];
SPFile file = fld.Files["Documents/MyFile.txt"];
//specific version
SPFileVersion version = file.Versions[1];
//Get the data
byte [] dBytes = version.OpenBinary();
Refer to the following posts for more information, hope it helps
http://blogs.msdn.com/b/karthick/archive/2006/03/28/563045.aspx
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8d2619bf-34e9-421b-85c1-792b2a9e8ae9/spfileversioncollection-specific-version?forum=sharepointdevelopmentlegacy
--Cheers -
Reading content of a file into an int array
How do i use FileReader rd = new FileReader(filename) to read the contents into an int array?
public static int[] parse_file(String filename)
Vector vec = new Vector();
int num[];
num = new num[vec.size()];
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
while((line = br.readLine()) != null) {
vec.add(line);
for (int i = 0; i < vec.size(); i++) {
num[i] = (int) vec.get(i);
System.out.println("Number=" + num);
catch(IOException e) {
System.out.println("error");
return num;
Maxsum.java:22: cannot resolve symbol
symbol : class num
location: class Maxsum
num = new num[vec.size()];
^
Maxsum.java:30: inconvertible types
found : java.lang.Object
required: int
num[i] = (int) vec.get(i);
How do i initialize the array?if i do not initialize it, there'll be array not initialized error also..How do i convert the String to int? -
Reading contents of .bin file created during backup function
I have a backup .bin file that I made with the online function on the Linksys WRT54GS router. The router failed and I replaced it with a WRT54G2 router and I can't load he .bin file from the GS into the G2. Is there a way to read the contents of the .bin file so I can put the parameters from the old router into the new one?
Probably not...the .bin file is an encrypted binary format (designed for security as there are router and wireless authentication passwords stored in it....
Tomato 1.25vpn3.4 (SgtPepperKSU MOD) on a Buffalo WHR-HP-G54
D-Link DSM-320 (Wired)
Wii (Wireless) - PS3 (Wired), PSP (Wireless) - XBox360 (Wired)
SonyBDP-S360 (Wired)
Linksys NSLU2 Firmware Unslung 6.10 Beta unslung to a 2Gb thumb, w/1 Maxtor OneTouch III 200Gb
IOmega StorCenter ix2 1TB NAS
Linksys WVC54G w/FW V2.12EU
and assorted wired and wireless PCs and laptops -
How can I read content from PDF file stored in Oracle 9i XMLDB
Hi Friends:
Now I have met one question that I don`t know how to read some String , for example "Hello", from the PDF file stored in the Oracle 9i XMLDB, I have stored that PDF file into the XMLDB now, any suggestions are appriciated . Thank you in advance.You may be able to do something with Oracle Text. The following shows how to get an HTML rendiditon of a binary document. I think you can also get plain text instead of HTML
set echo on
spool xfilesUtilties.log
connect sys/&1 as sysdba
grant ctxapp to &2
connect &2/&3
begin
ctxsys.ctx_ddl.create_policy(policy_name=>'XFILES_HTML_GENERATION', filter=>'ctxsys.auto_filter');
end;
create or replace package xfiles_internal_11010
authid definer
as
function renderAsHTML(sourceDoc BLOB) return CLOB;
end;
show errors
create or replace package body xfiles_internal_11010
as
function renderAsHTML(sourceDoc BLOB)
return CLOB
as
html_content CLOB;
begin
dbms_lob.createTemporary(html_content,true,DBMS_LOB.SESSION);
ctx_doc.policy_filter(policy_name => 'XFILES_HTML_GENERATION',
document => sourceDoc,
restab => html_content,
plaintext => false);
return html_content;
end;
end;
show errors
create or replace package xfiles_utilities_11010
authid current_user
as
HOME_FOLDER constant varchar2(700) := xdb_constants.HOME_FOLDER;
PUBLIC_FOLDER constant varchar2(700) := xdb_constants.PUBLIC_FOLDER;
function renderAsHTML(sourceFile VARCHAR2) return CLOB;
function transformToHTML(xmldoc XMLType, xslPath VARCHAR2) return CLOB;
end;
show errors
create or replace package body xfiles_utilities_11010
as
function renderAsHTML(sourceFile VARCHAR2)
return CLOB
as
begin
return xfiles_internal_11010.renderAsHTML(xdburitype(sourceFile).getBLOB());
end;
function transformToHTML(xmldoc XMLType, xslPath VARCHAR2)
return CLOB
as
html clob;
begin
select xmldoc.transform(xdburitype(xslPath).getXML()).getClobVal()
into HTML
from dual;
return html;
end;
end;
show errors
grant execute on xfiles_utilities_11010 to public
create or replace public synonym xfiles_utilities for xfiles_utilities_11010
quitMessage was edited by:
mdrake -
Read contents of file into outputstream
Can anyone suggest that what are the best methods to read contents of a file (better cater to both conditions: big file size and small file size) into outputstream and send through socket...
Thanks.Thanks for the answer. But I would like to ask the following question:
I have a VB application which generates a file. I have a Java application which read the contents of the file.
is it possible that VB side calls the read() (file) and send() (through socket to destination) methods in Java application once the file is generated? Actually my objective is VB is responsible for generating a file for Java application to read data from and then send the data (not file) to destination....If it is impossible to achieve, any alternative to achieve this?
Thanks
Edited by: whkhoo on Jun 15, 2008 8:45 PM -
Read content of file which is ZIPed
I need to read contents of a file which is present in ZIP file.
The zip file is present on online server. I am able to get the Zip Input stream for the Zip file and also able to retrive the file names which are present but when I am trying to retrive the content of file is get a String which has only the file names of the zip. Please suggest what to do.
Following is my Code.
// aConn.getInputStream() Gives me access to Zip file present on online Server
ZipInputStream fileIn = new ZipInputStream(aConn.getInputStream());
anEntry = inputStream.getNextEntry();
if (anEntry != null) {
String filename = arEntry.getFilename();
byte[] b = new byte[2024];
fileIn.read(b);
sb.append(b.toString());
}Reading an input stream into an array of bytes and then calling toString() on that byte array isn't going to give you the contents of the input stream meaningfully. For one thing it might not even be textual data. And secondly that's not how you get textual data.
A better approach would probably be to get the number of bytes of the given entry from the ZipEntry.getSize method, create a byte array of that size, load only that many bytes, and then (if you're sure it's text data) send the byte array to a String constructor. Or you could use a java.io.ByteArrayOutputStream for that. Note that you'll need to know the character encoding for this. -
Get the content of a file into a array
Hy to all!I have txt file with the following content : 0 1 1 0
1 1 1 0
0 0 0 0. I want to extract the values to a bi-dimension array,like this: a[0][0] = 0,a[0][1] = 1,a[0][2] = 1....and so on.
Anybody could give a little help.THXThe first thing I can help you with is that this doesn't have anything to do with java serialization.
Secondly, if you are new to java, the best forum is "New To Java" forum.
Thirdly, make sure you have done a google search first for an answer because it is likely that many people have asked the same question before.
The follow search gets over 2 million hits. [http://www.google.co.uk/search?q=java+read+content+of+a+file+into+a+array] -
Accidentally clicked on "Allow for Safe Networks Only" and saved it. When launching Firefox, this error: XML Parsing Error: no element found
Location: jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/toolkit.jar!/content/global/netError.xhtml
Line Number 1, Column 1:
I have uninstalled and reinstalled, changed to a new profile, nothing works. I have looked at Options - Network - No Proxy
Please help as I love FirefoxStart Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
* Don't make any changes on the Safe mode start window.
See:
* [[Troubleshooting extensions and themes]] -
Hi
I am trying to read contents of a pdf file .I used pdfbox it worked but the problem ,is for large pdf files it throws OutofMemory Exception
so i want to know how to read a pdf file line by line using pdfbox or any other API's
Thanksgkraju wrote:
It will work but
String x1= stripper.getText(doc);reads the whole document .so it will also throws exception if the file size is large.It might be an idea if you spent a few minutes considering the code fragment which was kindly posted. Your problem is that reading the whole file's text into memory uses up all the memory. Okay, that's a problem. So instead of whining here, why not consider what might fix that problem? The ridiculously obvious idea is to not read the whole file's text into memory. Can you figure out how to change the posted code to read, for example, only one page? If you can't figure that out then, really, perhaps you ought to consider doing something else instead of programming. -
Read data in file line by line
Hello,
I got a question to ask you all about reading file.
How do I read a file data line by line and than print out to the screen?
For example, my file file.txt content is:
my line 1
my line 2
the program will read the 2 line and print out to the screen.
thanks very muchThanks for your code but the code does not work. I can
compile the following code, but the content of the
file is not printed out yet.
Why is it so?Well, in addition to simply compiling the code, you have to execute it.
Also javajunior left open certain parts of the code, which you were supposed to finish. Like the exception handling and setting the filename variable. These are things that really only you can do.
Maybe you are looking for
-
Im looking for a specific how to on checking how much memory I have left on and external HD. Any help would be wonderful. V/R Chris
-
Separate details for Adjustment transaction files
Hi, As an out put from Time Evaluation I need to generate report for Oracle payroll office. For that I need to produce separate transcation file for adjustment days (post period regularization of attendance and absence days) of previous months. Can w
-
Email button from Order template conformation page.
hi, I got new requirement.in that i have to give give email button on Order template conformation page. if i click on email button new popup page will come and it will contain from email id,CC and messege. and i have to add entire item list in email.
-
Assigning Exposé to Unassignable Keys
Hi there. I have a Powerbook, so using Expose on F9 is hard, since the key is so small and out of the way. Is there a way I can switch it to the Enter key or the Arrow keys, which would be more convenient? I figure I'd have to get into some preferenc
-
hello ! i have an application wich interrogates my Oracle 8i Databse using OCI, my problem is that the number of rows returned is so large ( the totality of rows is 1 million) , how can i have rows returned by packets (as the same way as results retu