Problem in reading text file
Following is the text file(ocr.txt) from which i am reading data,
Name: mark
Date:1/11/2008
PO:4859685
Following is the program,
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class SkipWord {
public static void main(String args[])throws IOException{
FileReader fr = new FileReader("D:\\Kiran\\Programs\\ocr.txt");
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
String line1=br.readLine();
try{
Scanner s1=new Scanner(line).useDelimiter("\\s*name:\\s*date:\\s*po:\\s*");
System.out.println(s1.next());
System.out.println(s1.nextLine());
catch(NoSuchElementException e){}
Current output:
mark
But i want the output in the following way,
Expected output:
mark
1/11/2008
4859685
Please help me regarding this,its very urgent.
Thanks,
praveen
String line=br.readLine();
String line2=br.readLine();
Scanner s1=new Scanner(line).useDelimiter("\\s*name:\\s*date:\\s*po:
s*");
System.out.println(s1.next());
System.out.println(s1.nextLine());
Scanner s2=new Scanner(line1).useDelimiter("\\s*date:\\s*");
System.out.println(s2.next());
System.out.println(s2.nextLine());
I tried this but i am getting same output
Just printing "Mark".
Similar Messages
-
Problem in reading Text file(Unicode)
Hi
i am trying to read a tab delimited text file which has Unicode Encoding
try{
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(
"C:/Documents and Settings/divya.parkash/Desktop/Testting.txt"),
"UTF8"));
int buf;
while((buf=reader.read())>-1){
if (buf!=0)
str.append((char)buf);
System.out.println(str.toString());
catch (Exception e){System.out.println("Res: "+e);}
}but i am geting two ?? marks before the text
??STD_BIN HI 0 100 U10 21010100 66.550 20.000 1.000 1.200 1.200 1.300 0 100 RACKED 0 0
STD_BIN LO 21010200 100 U10 21010200 66.550 20.000 3.000 1.200 1.200 1.300 0 100 RACKED 0 0
STD_BIN LO 21010300 100 U10 21010300 66.550 20.000 5.000 1.200 1.200 1.300 0 100 RACKED 0 0
STD_BIN LO 21010400 100 U10 21010400 66.550 20.000 7.000 1.200 1.200 1.300 0 100 RACKED 0 0
STD_BIN LO 21010500 100 U10 21010500 66.550 20.000 9.000 1.200 1.200 1.300 0 0 RACKED 0 0
STD_BIN LO 21010600 100 U10 21010600 66.550 20.000 11.000 1.200 1.200 1.300 0 0 RACKED 0 0So please suggest me the reason and solutionHi
calvino_ind
this is the output i am getting by keeping buf as int.......
553365533838468956673789727394899494848985494895049484948494848932323232323254544653534893232323232325048464848489323232323232324946484848999932323232323232494650484893232323232323249465048489323232323232324946514848948932494848982656775696894894813108384689566737897679950494849485048489949484898549489504948494850484893232323232325454465353489323232323232504846484848932323232323232514648484899993232323232323249465048489323232323232324946504848932323232323232494651484894893249484898265677569689489481310838468956673789767995049484948514848994948489854948950494849485148489323232323232545446535348932323232323250484648484893232323232323253464848489999323232323232324946504848932323232323232494650484893232323232323249465148489489324948489826567756968948948131083846895667378976799504948494852484899494848985494895049484948524848932323232323254544653534893232323232325048464848489323232323232325546484848999932323232323232494650484893232323232323249465048489323232323232324946514848948932494848982656775696894894813108384689566737897679950494849485348489949484898549489504948494853484893232323232325454465353489323232323232504846484848932323232323232574648484899993232323232323249465048489323232323232324946504848932323232323232494651484894893232324898265677569689489481310838468956673789767995049484948544848994948489854948950494849485448489323232323232545446535348932323232323250484648484893232323232324949464848489999323232323232324946504848932323232323232494650484893232323232323249465148489489323232489826567756968948948131083846895667378976799504948494855484899494848985494895049484948554848932323232323254544653534893232323232325048464848489323232323232495146484848999932323232323232494650484893232323232323249465048489323232323232324946514848948932323248982656775696894894813108384689566737897679950494849485648489949484898549489504948494856484893232323232325454465353489323232323232504846484848932323232323249534648484899993232323232323249465048489323232323232324946504848932323232323232494651484894893232324898265677569689489481310 -
Problem While reading a file in text mode from Unix in ECC 5.0
Hi Experts,
I am working on Unicode Upgrade project of ECC5.0.
Here i got a problem with reading a file format which it does successfully in 4.6 and not in ECC5.0
My file format was as follows:
*4 000001862004060300000010###/#######L##########G/##########G/########
It was successfully converting corresponding field values in 4.6:
*4
00000186
2004
06
03
00000010
25
0
4
0
54.75
0
54.75
0.00
While i am getting some problem in ECC5.0 during conversion of the above line:
*4 000001862004060300000010###/#######L##########G/##########G/########
it was consider in the same # values.
I have used the following statement to open and read dataset.
OPEN DATASET i_dsn IN LEGACY TEXT MODE FOR INPUT.
READ DATASET i_dsn INTO pos_rec.
Thanks for your help.
Regards,
Gopinath Addepalli.Hi
You might be facing this problem because of uni code. So while opening or reading the file, there is a statement call ENCODING. Use that option and keep the code page which you want. Then the problem may be solved.
Thanks & Regards.
Harish. -
Indesign CS3-JS - Problem in reading text from a text file
Can anyone help me...
I have an problem with reading text from an txt file. By "readln" methot I can read only the first line of the text, is there any method to read the consecutive lines from the text file.
Currently I am using Indesign CS3 with Java Script (for PC).
My Java Script is as follows........
var myNewLinksFile = myFindFile("/Links/NewLinks.txt")
var myNewLinks = File(myNewLinksFile);
var a = myNewLinks.open("r", undefined, undefined);
myLine = myNewLinks.readln();
alert(myLine);
function myFindFile(myFilePath){
var myScriptFile = myGetScriptPath();
var myScriptFile = File(myScriptFile);
var myScriptFolder = myScriptFile.path;
myFilePath = myScriptFolder + myFilePath;
if(File(myFilePath).exists == false){
//Display a dialog.
myFilePath = File.openDialog("Choose the file containing your find/change list");
return myFilePath;
function myGetScriptPath(){
try{
myFile = app.activeScript;
catch(myError){
myFile = myError.fileName;
return myFile;
Thanks,
Bharath Raja GHi Bharath Raja G,
If you want to use readln, you'll have to iterate. I don't see a for loop in your example, so you're not iterating. To see how it works, take a closer look at FindChangeByList.jsx--you'll see that that script iterates to read the text file line by line (until it reaches the end of the file).
Thanks,
Ole -
i am not able to read text file in 10g forms. using webutil.pll and webutil.lib
here i posted the code . i am not getting message 2, client_text_io.fopen is not working what could be the reason.
DECLARE
in_file client_TEXT_IO.FILE_TYPE;
V_LINE_COUNT number;
linebuf VARCHAR2(1800);
V_var1 varchar2(80);
V_var2 varchar2(80);
V_var3 varchar2(80);
V_var4 varchar2(80);
V_var5 varchar2(80);
filename VARCHAR2(30);
l_var number;
blnRet BOOLEAN;
begin
DELETE FROM NIRU_TEMP;
:file_path:=LTRIM(RTRIM(:file_path));
MESSAGE('1');
in_file := client_text_io.fopen(UPPER(:file_path),'r');
MESSAGE('2');
loop
V_LINE_COUNT := V_LINE_COUNT + 1;
client_text_io.get_line(in_file,linebuf);
MESSAGE('5');
V_var1 := substr(linebuf,1,(instr(linebuf,',')-1)) ;
MESSAGE('6'||V_VAR1);
MESSAGE('6'||V_VAR1);
l_var := length(v_var1);
V_var2 := substr(linebuf,l_var+2,(instr(linebuf,','))) ;
--V_var3 := substr(linebuf,15 ,10 );
V_var2 :=LTRIM(RTRIM(V_var2));
MESSAGE('6'||V_var2);
MESSAGE('6'||V_var2);
:p_id := v_var1;
:p_desc :=v_var2;
--IF V_var2 = '' THEN
--V_var3 :='';
--else
--V_var3 := TO_NUMBER(V_var2) ;
--end if;
--V_var5 := substr(linebuf,26 ,70 );
INSERT INTO NIRU_TEMP VALUES (V_var1,V_var2);
client_text_io.new_line;
:System.Message_Level := '20';
commit;
:System.Message_Level := '0';
--<<end_loop>>
--null;
next_record;
end loop;
client_TEXT_IO.FCLOSE(in_file);
exception
WHEN OTHERS THEN
MESSAGE('ERROR'||SQLCODE||' '||SQLERRM);
--exit;
end;Hello Francois,
You have a solution for this problem?
I have a problem like this. While reading a text file, such as size of 7MB, long, between 15-30 minutes.
See...
declare
arq client_text_io.file_type;
linha varchar2(800);
v_total number := 0;
v_icms number := 0;
begin
:valor_total := 0;
:valor_icms := 0;
arq := client_text_io.fopen(:arquivo,'r');
loop
client_text_io.get_line(arq,linha);
if substr(linha,1,1) = '1' then
v_total := v_total + (to_number(substr(linha,302,13))/100);
v_icms := v_icms + (to_number(substr(linha,262,13))/100);
end if;
end loop;
client_text_io.fclose(arq);
exception
when no_data_found then
:valor_total := v_total;
:valor_icms := v_icms;
message('Realizado com sucesso!');
message('Realizado com sucesso!');
end; -
How to read text file contain chinese character ?
Hi XI Expert,
I have scenario to read text file contain Chinese Character using sender file adapter. but every i was check from sxmb_moni all the chinese character looks different. and also the target file also i has changes.
Please advise me how to maintaine the chinese character in PI 7.0 SP17.
Thank You and Best Regards
FernandHi,
Refer these threads..
Receiver file adapter corrupting characters
Problem in converting special characters in input text file
Here is one more useful guide..
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
Regards,
Sarvesh
Edited by: Sarvesh Singh on Nov 17, 2008 3:47 PM -
Read text file and insert into MySQL
Dears,
I need to read text file and then insert the data in the correct column in the MySQL database
example
I have the following text file:
field1=1234 field2=56789 field3=444555
field1=1333 field2=2222 field3=333555
and so on and so forth ,,note that all rows are identical and just the filed value is changed(there is a dilemeter between fields)
how can I read field1,field2 and field3 from text file and insert them in the correct table and column in the database.....
any help?????
thanks for your cooperation
Best RegarsSure.
Which part don't you understand?
1. Reading a text file
2. Parsing the text file contents.
3. Relational databases and SQL.
4. How to create a database.
5. How to connect to a database in Java.
6. How to insert records into the database in Java.
7. How to map Java objects to records in a database.
This is a pretty nice list. Solve complex problems by breaking them into smaller ones.
% -
How to create and read text file using LabVIEW 7.1 PDA module?
How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
I attach my code here.
Attachments:
File_IO.vi 82 KBWell my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.
-
I am facing problem to get text file from application sever
Hi This is lokesh.
Actually my requirement is to craete sales orders by getting file from other server.for that i have used shell script to connect that server.Ok i am connecting to that different server(not sap server) successfully.
But my problem is getting text file from application SERVER.
That different server people will send the file name as 'DDHHMMSS' (Days,Hours,Minutes,Seconds).
Just suppose if they will send today means that file name will come as 20103025. and with in half an hour if they again send that file file means that file name as '20110025'.
like that file name is always varies.So how can i read that type of text files from the application server.
and one more thing that is there chance to read morethan one text file from application server.
Pls guide me if u know the solution.PLs this requirement is urgent.
Regards,
LokeshgoudHi..,
<b>Just execute this program ... this is for the files received in JUST 3 MINS...</b>
change it according to your requirement !!
data time type sy-uzeit value '100000'. <i>"<<----start time</i>
data file(8) type c value '20'.
do 180 times. <i>" <<----- for 3 minutes</i>
add sy-index to time.
concatenate file time into file.
write / file.
OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC EQ 0.
PERFORM READ_DATASET.
ENDIF.
file = '20'.
time = '100000'.
ENDDO.
<b>form read_dataset.
read the file here with the file name <b>FILE</b>.
endform.</b>
regards,
sai ramesh -
HI,,,How to read text file from my emulators root
hi friends,
Actully i m having problem with file connection i.e. i cant read text file from my root of the emulator.....
i have tried like this...
plz help me out
String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/New Folder/main.txt";
InputConnection conn = (InputConnection)Connector.open( uri,Connector.READ );
InputStream in = conn.openInputStream();
conn.close();
for(int j=0;j<12;j++)
ch=in.read();
str.append((char)ch);
par1=str.toString();
in.close();
screen4.append(par1);
display.setCurrent(screen4);still its not working.........
String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/readme.txt";
FileConnection conn = (FileConnection)Connector.open( uri,Connector.READ);
InputStream in = conn.openInputStream();
conn.close();
String ss="";
String str1="";
int ch=0;
byte b[]=new byte[753];
ch=in.read(b,0,753);
str1= new String(b,0,ch);
ss=str1.substring(493,501);
screen4.append(ss);
display.setCurrent(screen4);
}catch(IOException io){} -
Problem while reading XML file from Aplication server(Al11)
Hi Experts
I am facing a problem while reading XML file from Aplication server using open data set.
OPEN DATASET v_dsn IN BINARY MODE FOR INPUT.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ DATASET v_dsn INTO v_rec.
WHILE sy-subrc <> 0.
ENDWHILE.
CLOSE DATASET v_dsn.
The XML file contains the details from an IDOC number , the expected output is XML file giving all the segments details in a single page and send the user in lotus note as an attachment, But in the present output after opening the attachment i am getting a single XML file which contains most of the segments ,but in the bottom part it is giving the below error .
- <E1EDT13 SEGMENT="1">
<QUALF>001</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803<The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'file:///C:/TEMP/notesD52F4D/SHPORD_0080005842.xml'.
/SPAN></NTEND>
<NTENZ>000000</NTENZ>
for all the xml its giving the error in bottom part , but once we open the source code and if we saved in system without changing anything the file giving the xml file without any error in that .
could any one can help to solve this issue .Hi Oliver
Thanx for your reply.
see the latest output
- <E1EDT13 SEGMENT="1">
<QUALF>003</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
- <E1EDT13 SEGMENT="1">
<QUALF>001</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803<The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'file:///C:/TEMP/notesD52F4D/~1922011.xml'.
/SPAN></NTEND>
<NTENZ>000000</NTENZ>
E1EDT13 with QUALF>003 and <E1EDT13 SEGMENT="1">
with <QUALF>001 having almost same segment data . but E1EDT13 with QUALF>003 is populating all segment data
properly ,but E1EDT13 with QUALF>001 is giving in between. -
Reading text file to JEditorPane
Hi,
I'm trying to read text file to JEditorPane and it works but first line is always missing. Here is the code for reading:
try {
in = new BufferedReader(new FileReader(filePathIn));
while ((lineIn = in.readLine()) != null) {
editorPane.read(in, new Object());
} catch (IOException ie)...Any suggestions?in.readLine is changing the input stream position.
Do this instead:
FileInputStream in = new FileInputStream(filePathIn);
while (in.available() != 0)
editorPane.read(in, new Object()); -
Problem in creating text file from report file
Hello Everybody...
I have problem in creating text file.
I had set System Parameter as below
DESTYPE : File
MODE : Character
DESNAME : gayu.txt
And ruler setting
Units : Character Cells
Character Cell Size : Horiziontal = 7
Vertiacle =12
GridSpacing : 1
no of snap points per grid spacing : 1
but when i run report it will give error
"REP_1219 M_2 or R_2 has no size -- length or width zero"
so is there any solution of that
or another way to convert report into text file?....Hi Folks,
Please don't go after that Error as its a very deceptive one. Please don't go for altering your design Or changing the size of items in your layout.
Similar errors I have come across in reports. I think its due to file transfer type. You might have transferred the file in Binary and your File Mode I am seeing it as CHAR.
This normally happens while making the Report Format as "Text". Either you change that format which I think is possible in your case as your basic requirement is making a report output of CHAR type.
Please check for this error in Metalink and proceed accordingly. I could fix similar errors when I changed Format type to PDF(from text).
Regards
Shibu -
How to read text file content in portal application?
Hi,
How do we read text file content in portal application?
Can anyone forward the code to do do?
Regards,
AnaghaCheck the code below. This help you to know how to read the text file content line by line. You can display as you require.
IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
IResourceContext resourceContext = new ResourceContext(user);
String filePath = "/documents/....";
RID rid = RID.getRID(filePath);
IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
InputStream inputStream = resource.getContent().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
while(line!=null) {
line = reader.readLine();
//You can append in string buffer to get file content as string object//
Regards,
Yoga -
How can I read text files from LAN if I only know the hostname?
I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
<p>1. How can I read text files from LAN if I only know the hostname, or IP address?
<p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
(ex. how can I read the 120th line?)
<p>Please help!
<p>sorry for the bad englishI'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
The hostname is server, not file.
2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
(ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is
Maybe you are looking for
-
Sound not working for text alert just vibrate
Sound not working for text alert just vibrate and no sound on keyboard
-
Licence cs6 changed in a trial
licence cs6 changed in a trial. How can I get my cs6 back. My activationcode does not work anymore
-
I purchased Aperture 3 pre-App Store. I recently bought a new MacBook Retina and I want to download and install a fresh copy of Aperture. However all the download links are for point release updates. Which is the last full up-to-date version to downl
-
Missing Font on Devices Page in Itunes
I'm still having issues with my font on the device page in itunes 10.1. I've updated my font and that fixed half of my problems. I ran a font patch for windows vista and that didn't help. Before I updated my font, all text was missing on the device p
-
Hi All, When Administrator changing user's password from OIM, system is setting in OID a flag called "obpasswordchangeflag=true". So that user need to change his/her password in next login. but my requirement, we do not need this feature turned on. H