How to read number of ';' in a text file
I have a text file with size 2kb. The file has names seperated by ';' . For example John, Smith; David, Putnam; etc ..
Now I have to read the file and find out how many ';' are there.
I tried GUI_upload to read the text file and I think I did not get whole data.
and
loop at itab.
if itab-names cs ';' .
find ALL OCCURRENCES OF REGEX ';' IN itab-names MATCH COUNT mcnt.
l_mstring = itab-names .
endif.
endloop.
I'm just getting count as 3
Edited by: P V on Feb 21, 2008 9:57 PM
DATA : tot_count TYPE i,
mcnt TYPE i.
loop at itab.
if itab-names cs ';' .
find ALL OCCURRENCES OF REGEX ';' IN itab-names MATCH COUNT mcnt.
tot_count = tot_count + mcnt.
endif.
endloop.
You will get total number of ; available in file in the field tot_count.
Regards
Sudhir Atluru
Similar Messages
-
How to read the content of a text file (by character)?
Guys,
Good day!
I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
Please help me. Thank you so much in advance.
Jojohttp://java.sun.com/javase/6/docs/api/index.html
package java.io
InputStream.read(): int
Reads the next byte of data from the input stream.
Implementation:
InputStreamReader
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. -
How to read every line from a text file???
How can i read every line from my text file ("eka.txt")
now it only reads the first line and prints it out.
What is wrong with this?
import java.io.*;
import java.util.*;
class Testi{
public static void main(String []args)throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
File inputFile = new File ("eka.txt");
FileReader fis =new FileReader(inputFile);
BufferedReader bis = new BufferedReader(fis);
String test=bis.readLine();
String tmp= "";
while((bis.readLine().trim() != null)) {
int spacefound=0;
int l=test.indexOf(" ");
for(int i=0;i<test.length();i++){
char c=test.charAt(i);
if(c!=' ') tmp+=""+c;
if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
tmp+=""+c;
spacefound++;
if(tmp.length()==l) {
System.out.println(tmp);
tmp="";
spacefound=0;
if(tmp.length()<l){
for(int i=0;i<=(l-tmp.length());i++)
tmp+=""+' ';
System.out.println(tmp);Try this code, Hope it servers your purpose.
import java.io.*;
import java.util.*;
class Testi {
public static void main(String []args)throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
File inputFile = new File ("Eka.txt");
FileReader fis =new FileReader(inputFile);
BufferedReader bis = new BufferedReader(fis);
String test=bis.readLine();
while(test != null) {
StringTokenizer st = new StringTokenizer(test," ");
while(st.hasMoreTokens())
System.out.println(st.nextToken());
test = bis.readLine();
}Sudha -
How to read some lines from a text file using java.
hi,
i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
we only want to read the file upto the first Occurrence of "TEXT" string.
How to do it ,,,
Kinldy give the code
Regards,
Sagar
this is the text file
dfgjdjj
sfjhjkd
ghjkdg
hjkdgh TEXT
ikeyt
ujt
jk
tyk TEXT
rukl
rHendawy wrote:
Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
Edited by: sabre150 on Apr 29, 2009 2:13 PM -
How to read some records from a text file into java(not all records)
hello,
how to read text files into java. i need only few records from the text file not all records at a time.
If any one knows plz reply me
my id is [email protected]this snipet reads a text file line by line from line 1 to 3
try {
FileReader fr = new FileReader(directory);
BufferedReader br = new BufferedReader(fr);
int counter = 0;
while ((dbconn = br.readLine()) != null) {
switch(counter){
case 0:
status = dbconn;
break;
case 1:
userName = dbconn;
break;
case 2:
apword = dbconn;
break;
counter++;
br.close();
}catch(IOException e){
} -
How to read the contents of a text file and populate the data in a table ?
Hello All,
Can anyone advise on how to acheieve the above ? I am trying to read in a text file (CSV) and have the contents populated to the respective UI elements in a table. Any help is greatly appreciated.
from
Kwok WeiHi,
Let us consider you have list of names(Seperated by delimeter) in a text file and you want to display in a table.
1. Create Context Node "Names" and context attribute "Name"
2. Create Table and bind to the above context.
3.Write the following code in the "Init method.
try{
FileReader f =new FileReader("");
BufferedReader r=new BufferedReader(f);
String names=r.readLine();
Vector Names=new Vector();
// Use Tokenizer and store all the names i a vector//
for(int i=0;i<Names.size();i++){
IPrivate<<VieName>>.INameElement ele=wdContext.createNameElement();
ele.set<<Name>>( Names.get(i).toString());
wdContext.NodeName().addElement(ele);
Regards, Anilkumar
Message was edited by: Anilkumar Vippagunta -
How to read specific lines from a text file using external table or any other method?
Hi,
I have a text file with delimited data, I have to pick only odd number rows and load into a table...
Ex:
row1: 1,2,2,3,3,34,4,4,4,5,5,5,,,5 ( have to load only this row)
row2: 8,9,878,78,657,575,7,5,,,7,7
Hope this is enough..
I am using Oracle 11.2.0 version...
ThanksThere are various ways to do this. I would be inclined to use SQL*Loader. That way you can load it from the client or the server and you can use a SQL*Loader sequence to preserve the row order in the text file. I would load the whole row as a varray into a staging table, then use the TABLE and MOD functions to load the individual numbers from only the odd rows. Please see the demonstration below.
SCOTT@orcl12c> HOST TYPE text_file.csv
1,2,2,3,3,34,4,4,4,5,5,5,,,5
8,9,878,78,657,575,7,5,,,7,7
101,201
102,202
SCOTT@orcl12c> HOST TYPE test.ctl
LOAD DATA
INFILE text_file.csv
INTO TABLE staging
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(whole_row VARRAY TERMINATED BY '/n' (x INTEGER EXTERNAL),
rn SEQUENCE)
SCOTT@orcl12c> CREATE TABLE staging
2 (rn NUMBER,
3 whole_row SYS.OdciNumberList)
4 /
Table created.
SCOTT@orcl12c> HOST SQLLDR scott/tiger CONTROL=test.ctl LOG=test.log
SQL*Loader: Release 12.1.0.1.0 - Production on Tue Aug 27 13:48:37 2013
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 4
Table STAGING:
4 Rows successfully loaded.
Check the log file:
test.log
for more information about the load.
SCOTT@orcl12c> CREATE TABLE a_table
2 (rn NUMBER,
3 data NUMBER)
4 /
Table created.
SCOTT@orcl12c> INSERT INTO a_table (rn, data)
2 SELECT s.rn,
3 t.COLUMN_VALUE data
4 FROM staging s,
5 TABLE (s.whole_row) t
6 WHERE MOD (rn, 2) != 0
7 /
17 rows created.
SCOTT@orcl12c> SELECT * FROM a_table
2 /
RN DATA
1 1
1 2
1 2
1 3
1 3
1 34
1 4
1 4
1 4
1 5
1 5
1 5
1
1
1 5
3 101
3 201
17 rows selected. -
How to read numeric array from a text file
I'm new to file I/O in LabView. Basically, all I need is to read the attached 2000 x 9 array into an identical 2D array within LabView. I have tried simply using the READ FROM SPREADSHEET FILE VI but it only reads the first column. Any help would be greatly appreciated.
Thanks, Hunter
Attachments:
FRFx1.dat 286 KBI cant open theother examples, so maybe I`m posting something similar, but here`s my approach in LV 6.1
First convert all double spaces to single spaces, then all single spaces to tab. Then use "Spreadsheet string to array" cutting out the first column (extra tabs produce an extra column).
Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Attachments:
Read_in_Matlab_file(6.1).vi 26 KB -
Reading and writing to a text file from an Applet
I'm a novice java programming with very little formal programming training. I've pieced together enough knowledge to do what I've wanted to do so far...
However, I've been unable to figure out how to read and write to a text file from an Applet (I can do it from a normal java program just fine). Here is a simple example of what I'd like to do (you can also look at it on my website: www.stat.colostate.edu/~leach/test02/test02.html). I know that there is some problem with permission/security but I'm not smart enough to understand what the error messages are telling or understand the few books I have. If anyone can tell me how to get this applet to work, or direct me to some referrences that would help me out I'd really appreciate it.
Thanks,
Andy
import java.applet.Applet;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class test02 extends Applet {
public Button B_go;
public GridBagConstraints c;
public void init() {
this.setLayout(new GridBagLayout());
c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
B_go = new Button("GO");
c.gridx=1; c.gridy=0; c.gridwidth=1; c.gridheight=1;
c.weightx = c.weighty = 0.0;
B_go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
print_stuff();
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
this.add(B_go,c);
public static void print_stuff() {
try{
File f = new File("test02.txt");
PrintWriter out = new PrintWriter(new FileWriter(f));
out.print("This is test02.txt");
out.close();
}catch(IOException e){**/}
}I have almost the exact same problem, and I am in the same situation as you are with respects to the language.
I am simply trying to create a file and output some garbage to it but my applet always spits back a security violation. I've tried eliminating the restrictions on the applet runner I use but I still get the error.
My method:
debug = new Label() ;
debug.setLocation( 20, 20 ) ;
debug.setSize( 500, 15 ) ;
add( debug ) ;
// output
try
OutputStream file = new FileOutputStream( new File( "" + getCodeBase() + "output.txt" ) ) ;
byte[] buffer = { 1, 2, 3, 4, 5 } ;
file.write( buffer ) ;
file.close() ;
} catch( Exception e )
debug.setText( e.toString() ) ;
Can anyone tell why this isnt working? -
How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap? Currently my program reads the data from several text files in a directory and the saves that information in a text file called output.txt. I would like to cache this data in order to use it later. How can I do this using the TreeMap Class? These are the keys,values: TreeMap The data I'd like to Cache is (date from the file, time of the file, current time).
import java.io.*;
public class CacheData {
public static void main(String[] args) throws IOException {
String target_dir = "C:\\Files";
String output = "C:\\Files\output.txt";
File dir = new File(target_dir);
File[] files = dir.listFiles();
// open the Printwriter before your loop
PrintWriter outputStream = new PrintWriter(output);
for (File textfiles : files) {
if (textfiles.isFile() && textfiles.getName().endsWith(".txt")) {
BufferedReader inputStream = null;
// close the outputstream after the loop
outputStream.close();
try {
inputStream = new BufferedReader(new FileReader(textfiles));
String line;
while ((line = inputStream.readLine()) != null) {
System.out.println(line);
// Write Content
outputStream.println(line);
} finally {
if (inputStream != null) {
inputStream.close();How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap? Currently my program reads the data from several text files in a directory and the saves that information in a text file called output.txt. I would like to cache this data in order to use it later. How can I do this using the TreeMap Class?
I don't understand your question.
If you don't know how to use TreeMap why do you think a TreeMap is the correct solution for what you want to do?
If you are just asking how to use TreeMap then there are PLENTY of tutorials on the internet and the Java API provides the methods that area available.
TreeMap (Java Platform SE 7 )
Are you sure you want a map and not a tree instead?
https://docs.oracle.com/javase/tutorial/uiswing/components/tree.html -
How do i read complete line from a text file in j2me?????
how do i read complete line from a text file in j2me????? I wanna read file line by line not char by char..Even i tried with readUTF of datainputstream to read word by word but i got UTFDataFormatException.. Please solve my problem.. Thanks in advance..
That is not my problem . i already read it char by char.. i am getting complete line..But this process is taking to much time..So thats why i directly wanna read complete line or word to save time..
-
How to read and write data from json file from windows phone7 app
Hi
I am developing wp7 app for the use of students my questions are
How can i write a code to read and write the json/text file for the wp7.
I am using windows 7 OS, VS 2010 Edition.
This is my code below:
xaml:
<Grid>
<TextBlock Height="45" HorizontalAlignment="Left" Margin="7,18,0,550" Name="textBlock1" Text="Full
Name: " />
<TextBox Width="350" Height="70" HorizontalAlignment="Left" Margin="108,1,0,0" Name="txtName"
Text="Enter your full name" VerticalAlignment="Top" />
<TextBlock Height="45" HorizontalAlignment="Left" Margin="6,75,0,0" Name="textBlock2" Text="Contact
No: " VerticalAlignment="Top" />
<TextBox Width="350" Height="70" HorizontalAlignment="Left" Margin="108,61,0,480" Name="txtContact"
Text="Enter your contact number" MaxLength="10" />
<Button Content="Register" Height="72" HorizontalAlignment="Left" Margin="10,330,0,0" Name="btnRegister"
VerticalAlignment="Top" Width="190" Click="btnRegister_Click" />
</Grid>
xaml.cs:
private void btnRegister_Click(object sender, RoutedEventArgs e)
string name, contact;
name = txtName.Text;
contact = txtContact.Text;
try
if (name != "" && contact != "")
string msg = name + " " + contact;
MessageBox.Show(msg);
Student stud = new Student
Name= name,
Contact = contact,
string jsonString = JsonConvert.SerializeObject(stud);
MessageBox.Show(jsonString);
else
MessageBox.Show("Input Proper Information", MessageBoxButton.OK);
catch (Exception ex)
MessageBox.Show(ex.Message);
I have download NewtonSoft.json version 5.0.8.
So, I am able to convert input data into json format, but how can I able to write and read this data from a json/text file.
How can I do?
Thank you in adv and please, reply soon.We don't have many samples left for Windows Phone 7 + Azure, the closest one to what you want to do is probably:
Using Local Storage with OData on Windows Phone To Reduce Network Bandwidth
this sample uses the local database feature: 'LINQ to SQL', available to Windows Phone 7.1 and 8.0 Silverlight applications, instead of simple file storage but even if you choose to stick with simple file storage I believe you should be able to adapt the
networking related portions of the sample to your particular application.
Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast
your votes for existing suggestions. -
How to read iCal events from SQLite Cache file?
I need to figure out how to read event entries in the Cache file stored in /Library/Calenders/ as my actual events have been corrupted due to a file system problem. The example below shows the information I have for each entry, where the event in the entry was Bon Jovi Concert, however I am confused how I can read the date and time of the event, information I believe is stored as 218215639,219613081,219524400,219540600. Any help is greatly appreciated.
INSERT INTO "ZCALENDARITEM" VALUES(0,NULL,0,NULL,0,5,NULL,6,4039,NULL,0,0,0,0,0,0,2,23,0,0,0,0,6,0,21821563 9,219613081,219524400,219540600,NULL,NULL,NULL,NULL,NULL,'local_AFB8D342-2DAE-4F A1-A9A6-3FA9B28B5C7C','Bon Jovi Concert',NULL,NULL,NULL,'Europe/London',NULL,'0E17BBB6-0E76-4024-8DD7-60E43D38D 35B');OK, here we go ... I hope. I have tried it on my iCal, with about 2000 entries, and it worked. I cannot guarantee that it will work for you.
Make a new text file from sql as before, but using this modified command to get additional data for each event:
sqlite3 Desktop/Hope 'select ZSTARTDATE, ZCALENDARITEM.ZTITLE, ZENDDATE, ZNODE.ZTITLE, ZISALLDAY, ZRECURRENCERULE, ZISDETACHED from ZCALENDARITEM inner join ZNODE on ZCALENDARITEM.ZCALENDAR = ZNODE.Z_PK where ZSTARTDATE not null' >hope.txt
I suggest you make a new user account, then copy the text file hope.txt and the script to the Public/Drop Box folder for that account. Log on to the new account and copy the two files from the drop box to the Desktop. Start iCal and make new calendars to match those in your ordinary account. Double click the script to open it in Script Editor and CHANGE THE DATE RANGE in the "set ThePeriod" line. Stand well back and click the run button. Every 50 records processed it will pop up a progress box, which will pop down again after a second. Go for lunch.
When it is finished see if things look OK in iCal. If they do export each of the calendars, copy them to the drop box of your normal account and return to your normal account to import them.
If there is an error make a note of the error message and line number, find that line in the text file, and post it here with a couple of lines either side.
Note that for recurring items iCal normally only makes a single event, the first occurrence, then uses a recurrence rule to calculate if the event should be displayed in the current window. If there are any recurring events in the period you have selected where the first occurrence is before the period they will not be recreated. Where however you have changed a single occurrence of a recurring event iCal makes a new, detached, event. Any of these in the period will be detected. If their original event was also in the period they will now appear in the iCal display as duplicates. For easy spotting of these, I have prefixed "XX-" to the title of any detached events.
AK
<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">on run
set ThePeriod to {date ("jan 1 2008"), date ("dec 31 2008")} --CHANGE THIS BEFORE RUNNIN
set TheFile to open for access (path to desktop as text) & "temp.txt"
set TheContents to read TheFile --until return
close TheFile
set TheLines to paragraphs of TheContents
set OldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"|"}
set LCount to 0
set ACount to 0
set RCount to 0
set DCount to 0
set SCount to 0
set HowMany to (count of TheLines)
try
repeat with ThisLine in TheLines
if (count of ThisLine) is 0 then exit repeat
-- Start Date, Title, End Date, Calendar, All Day, Recurs, Detached
set LCount to LCount + 1
set Details to text items of ThisLine
set MyStartDate to FixMyDate(item 1 of Details)
set MyTitle to item 2 of Details
set MyEndDate to FixMyDate(item 3 of Details)
set MyCalendar to item 4 of Details
set MyAllDay to item 5 of Details
set MyRecurs to item 6 of Details
set MyDetached to item 7 of Details
if MyAllDay is "1" then set ACount to ACount + 1
if (count of MyRecurs) > 0 then set RCount to RCount + 1
if MyDetached is "1" then set MyTitle to "XX-" & MyTitle
if MyDetached is "1" then set DCount to DCount + 1
if (MyCalendar is not "Birthdays") and (MyStartDate ≥ item 1 of ThePeriod) and (MyStartDate ≤ item 2 of ThePeriod) then
tell application "iCal"
tell calendar MyCalendar
set ThisItem to make new event at end of events with properties {summary:MyTitle, start date:MyStartDate}
end tell
tell ThisItem
if MyAllDay is "1" then set allday event to true
if (count of MyRecurs) > 0 then set recurrence to MyRecurs
set end date to MyEndDate
end tell
end tell
else
set SCount to SCount + 1
end if
if (LCount mod 50) = 0 then
set the_message to "Processed " & (LCount as string) & " of " & (HowMany as string)
display dialog the_message buttons {"Cancel"} giving up after 1
end if
end repeat
on error TheError
display dialog "Error: " & TheError & " about line " & LCount
end try
set AppleScript's text item delimiters to OldDelim
display dialog (LCount as string) & " lines processed" & return & "All Day: " & (ACount as string) & return & "Recurs: " & (RCount as string) & return & "Detach: " & (DCount as string) & return & "Skipped: " & (SCount as string)
end run
on FixMyDate(MyDate)
date (do shell script "date -r " & MyDate & " -v+31y +%e'/'%m'/'%y' '%T")
end FixMyDate
</pre> -
How to read the and Write the PDF file give me the solution
Hi all,
How to read the and Write the PDF file give me the solution
My coding is
import java.io.File;
import com.asprise.util.pdf.PDFImageWriter;
import com.asprise.util.pdf.PDFReader;
import java.io.*;
import java.io.FileOutputStream;
public class example {
// public example() {
public static void main(String a[])
try
PDFReader reader = new PDFReader(new File("C:\\AsprisePDF-DevGuide.pdf"));
reader.open(); // open the file.
int pages = reader.getNumberOfPages();
for(int i=0; i < pages; i++) {
String text = reader.extractTextFromPage(i);
System.out.println("Page " + i + ": " + text);
// perform other operations on pages.
PDFImageWriter writer = new PDFImageWriter(new FileOutputStream("c:\\new11.pdf"));
writer.open();
writer.addImage("C:\\sam.doc");
writer.close();
System.out.println("DONE.");
reader.close();
catch(Exception e){System.out.println("error:"+e);
e.printStackTrace();
I get the pdf content then it returns the string value but ther is no option to write the string to PDF, and we only add a image file to PDF,but i want to know how to wrote the string value to PDF file,
Please give response immtly
i am waiting for your reply.
thanks,
Suresh.GI have some question flow
How library to use this code.
I try runing but have not libary.
Please send me it'library
Thank you very much! -
Reading Each String From a text File
Hello everyone...,
I've a doubt in File...cos am not aware of File.....Could anyone
plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help meThe Java� Tutorials > Essential Classes: Basic I/O
Maybe you are looking for
-
How to use 10 touch points at the same time ?
I want to project game which use about 10 touch points? How can I use all of them at the same time ? Please give me a sample code.
-
We have a need to generate 997 Functional Ack for 856 inbound with AK5 status as E (Accepted with Error) instead of R (Rejected) for some data Error codes in (ST & SE segments only ) . To make this work ,we modified the SeverityConfig.xml file for ED
-
Help I tried upgrading to itunes8 and now my quicktime player has dissapear
Hi can anyone help, i clicked the option to upgrade to the latest version, it didn't work correctly, the "help" option told me to uninstall and reinstall quicktime, i uninstalled and now it wont let me re-install! I just want my library back. my emai
-
Pls. Help me "ARXAGMW.rdf".
I'm customize standard report of oracle apps. The report is "ARXAGMW.rdf". I'm get message REP-0773: No Source specified for Parameter Form Field 'PF_p_claim_option'. In property Inspector --> Parameter Form Field, the source is null. Please tell me
-
Dropdown crashes applications...
I'm using Tiger 10.4.7 and whenever I'm using Adobe Photoshop, Illustrator or Acrobat and try to use the dropdown menu in the save or open dialogs it crashes the application. It also does not remember any recent places, so when I want to save it alwa