Putting words from a text file into a binary tree.
I am having problems figuring out how to do this.
the text file will have a sentence like this
Every one likes to play games.
My Dog tore up my apartment last night.
How old are you sir.I know how to put regular strings into a binary tree, but I don't know what to do in order to put these textfile strings into it.
I thought of using string tokenizer but I couldn't get that to work because the sentences are not a specific length, they can be any length. Can somebody give me some tips on what to use?
Thank you
JulianJ wrote:
That will work?I'm sorry to tell you, that is a really bad question. Of course it won't work, because you did something else wrong. I have no idea what, but it's pretty certain that you haven't got everything right yet. (And that's nothing personal, it's just an observation about computer programming in general.) But don't let that stop you. And don't wait around for people to validate your ideas. Try it and see what happens. You won't break anything. And when it doesn't work, figure out why and carry on.
Similar Messages
-
Read words from a text file into an undefined array
Dear all,
Does anyone know how to read words in text file, seperated by all types of spaces ("_", "\n", "\t","\r","\f") and put them into a string array to be used later?
So far I can read the words using the Tokenizer but can't assign to array:
public class reader
StringTokenizer tokenizer = new StringTokenizer(input);
String[ ] array= null; //unknown size of array
int i=0;
while(tokenizer.hasMoreTokens())
array[i] = tokenizer.nextToken();
i++;
Any suggestions welcome!
thanks in advance!Hi
sorry wrote in a hurry ;) din c the problem clearly
there are two approaches
1) best approach for your problem is Vector or ArrayList, these would make life easy for you.
Always collections are better approach over arrays when the size is dynamic. However in your case the size cant be said to be DYNAMIC. coz the number of words will not grow / shrink during the runtime.. i know that number of words are not fixed but dynamic is something which will grow/shrink during runtime. but still collection is better approach.
2)dirty approach
use double dimensional array
String arr[][] = null;
then use one tokenizer for StringTokenizer(str,"\n");
using countTokens on this will give you number of lines.
use this to initialize array
arr = new String[lineCount][];
then iterate from 1 to lineCount and use 1 more tokenizer to get number of words for that line. use this number to initialize the column size for arr[i] like
arr[i] = new String[wordCount];
then store the token using nested for loops in this array
go for the 1st one ;) 2nd one is hedious n time consuming but both will work ;)
cheers
amey -
Reading one line from a text file into an array
i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
public static void readAndProcessData(FileInputStream stream){
InputStreamReader iStrReader = new InputStreamReader (stream);
BufferedReader reader = new BufferedReader (iStrReader);
String line = "";
try{
int i = 0;
while (line != null){
names[i] = reader.readLine();
score[i] = reader.readLine();
line = reader.readLine();
i++;
}catch (IOException e){
System.out.println("Error in file access");
this section calls it:
try{
FileInputStream stream = new FileInputStream("ISU.txt");
HighScore.readAndProcessData(stream);
stream.close();
names = HighScore.getNames();
scores = HighScore.getScores();
}catch(IOException e){
System.out.println("Error in accessing file." + e.toString());
it gives me an array index out of bounds erroroh wait I see it when I looked at the original quote.
They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens. -
SQL Loader-How to insert -ve & date values from flat text file into coloumn
Question: How to insert -ve & date values from flat text file into coloumns in a table.
Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
How to load such values in columns of database using SQL Loader?
Please guide.Question: How to insert -ve & date values from flat text file into coloumns in a table.
Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
How to load such values in columns of database using SQL Loader?
Please guide. Try something like
someDate DATE 'DDMMYYYY'
someNumber1 "TO_NUMBER ('s99999999.00')"
someNumber2 "TO_NUMBER ('99999999.00s')"Good luck,
Eric Kamradt -
Reading from a text file into a 2D array
How do you read from a text file and put it into a 2D array? Or if someone could guide me to where I can find the information?
This tutorial shows how to read a file:
http://java.sun.com/docs/books/tutorial/essential/io/scanfor.html
This tutorial shows how to create arrays with multiple dimensions:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html -
How to import data from a text file into a table
Hello,
I need help with importing data from a .csv file with comma delimiter into a table.
I've been struggling to figure out how to use the "Import from Files" wizard in Oracle 10g web-base Enterprise Manager.
I have not been able to find a simple instruction on how to use the Wizard.
I have looked at the Oracle Database Utilities - Overview of Oracle Data Pump and the Help on the "Import: Files" page.
Neither one gave me enough instruction to be able to do the import successfully.
Using the "Import from file" wizard, I created a Directory Object using the Create Directory Object button. I Copied the file from which i needed to import the data into the Operating System Directory i had defined in the Create Directory Object page. I chose "Entire files" for the Import type.
Step 1 of 4 is the "Import:Re-Mapping" page, I have no idea what i need to do on this page. All i know i am not tying to import data that was in one schema into a different schema and I am not importing data that was in one tablespace into a different tablespace and i am not R-Mapping datafiles either. I am importing data from a csv file.
For step 2 of 4, "Import:Options" page, I selected the same directory object i had created.
For step 3 of 4, I entered a job name and a description and selected Start Immediately option.
What i noticed going through the wizard, the wizard never asked into which table do i want to import the data.
I submitted the job and I got ORA-31619 invalid dump file error.
I was sure that the wizard was going to fail when it never asked me into which table do i want to import the data.
I tried to use the "imp" utility in command-line window.
After I entered (imp), i was prompted for the username and the password and then the buffer size as soon as i entered the min buffer size I got the following error and the import was terminated:
C:\>imp
Import: Release 10.1.0.2.0 - Production on Fri Jul 9 12:56:11 2004
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Username: user1
Password:
Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
tion
With the Partitioning, OLAP and Data Mining options
Import file: EXPDAT.DMP > c:\securParms\securParms.csv
Enter insert buffer size (minimum is 8192) 30720> 8192
IMP-00037: Character set marker unknown
IMP-00000: Import terminated unsuccessfully
Please show me the easiest way to import a text file into a table. How complex could it be to do a simple import into a table using a text file?
We are testing our application against both an Oracle database and a MSSQLServer 2000 database.
I was able to import the data into a table in MSSQLServer database and I can say that anybody with no experience could easily do an export/import in MSSQLServer 2000.
I appreciate if someone could show me how to the import from a file into a table!
Thanks,
Mitra>
I can say that anybody with
no experience could easily do an export/import in
MSSQLServer 2000.
Anybody with no experience should not mess up my Oracle Databases ! -
Reading characters from a text file into a multidimensional array?
I have an array, maze[][] that is to be filled with characters from a text file. I've got most of the program worked out (i think) but can't test it because I am reading my file incorrectly. However, I'm running into major headaches with this part of the program.
The text file looks like this: (It is meant to be a maze, 19 is the size of the maze(assumed to be square). is free space, # is block, s is start, x is finish)
This didn't paste evenly, but thats not a big deal. Just giving an idea.
19
5..................
And my constructor looks like follows, I've tried zillions of things with the input.hasNext() and hasNextLine() to no avail.
Code:
//Scanner to read file
Scanner input = null;
try{
input = new Scanner(fileName);
}catch(RuntimeException e) {
System.err.println("Couldn't find the file");
System.exit(0);
//Set the size of the maze
while(input.hasNextInt())
size = input.nextInt();
//Set Limits on coordinates
Coordinates.setLimits(size);
//Set the maze[][] array equal to this size
maze = new char[size][size];
//Fill the Array with maze values
for(int i = 0; i < maze.length; i++)
for(int x = 0; x < maze.length; x++)
if(input.hasNextLine())
String insert = input.nextLine();
maze[i][x] = insert.charAt(x);
Any advice would be loved =DCode-tags sometimes cause wonders, I replaced # with *, as the code tags interprets # as comment, which looks odd:
******...*.........To your code: Did you test it step by step, to find out about what is read? You could either use a debugger (e.g., if you have an IDE) or system outs to get a clue. First thing to check would be, if the maze size is read correctly. Further, the following loops look odd:for(int i = 0; i < maze.length; i++) {
for(int x = 0; x < maze.length; x++) {
if (input.hasNextLine()) {
String insert = input.nextLine();
maze[x] = insert.charAt(x);
}Shouldn't the nextLine test and assignment be in the outer loop? And assignment be to each maze's inner array? Like so:for(int i = 0; i < maze.length; i++) {
if (input.hasNextLine()) {
String insert = input.nextLine();
for(int x = 0; x < insert.size(); x++) {
maze[i][x] = insert.charAt(x);
}Otherwise, only one character per line is read and storing a character actually should fail. -
How do you read data from a text file into a JTextArea?
I'm working on a blogging program and I need to add data from a text file named messages.txt into a JTextArea named messages. How do I go about doing this?
Student_Coder wrote:
1) Read the file messages.txt into a String
2) Initialize messages with the String as the textSwing text components are designed to use Unix-style linefeeds (\n) as line separators. If the text file happens to use a different style, like DOS's carriage-return+linefeed (\r\n), it needs to be converted. The read() method does that, and it saves the info about the line separator style in the Document so the write() method can re-convert it.
lethalwire wrote:
They have 2 different ways of importing documents in this link:
http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
Neither of those methods applies to JTextAreas. -
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 do import data from the text file into the mathscript window?
Could anyone tell me how to do import data from text file into mathscript window for labview 8?
MathScript Window openned, File, Load Data - it has options: custom pattern (*.mlv) or all files.
ThanksHi Milan,
Prior to loading data in Mathscript Window , you have to save the data from the Mathscript window (the default extension of the file is .mlv but you can choose any extension). This means that you cannot load data from a text file that was not created using the Mathscript window.
Please let me know if you have any further questions regarding this issue.
Regards,
Ankita -
Reading data from a text file into PAS - Dimension member names truncated
Hi,
I created a procedure to dump variables and data into a text file to load into another model. I used a semicolon as a field seperator.
The data, measures and dimension members are dumped properly into a text file and no dimension member names are truncated .
However when I read the data into a measure, and I issue a peek command, dimension meber names are read in truncated
and remain full names in the text file. Any reason for this? What do I need to do to prevent this from happening?
THanks.
LungileHi Lungile,
The problem that you're likely having is that you haven't created a file description for the file from which you're reading. When loading data into Application Server from a text file, you would normally go through three steps:
1. Enter the ACCESS EXTERNAL subsystem
2. Specify the name of the file to be read
3. Specify the format of the file field names, types, widths, and positions.
If you go into the Application Server help, select "Application Server Help", then "Application Server at the command level", then "Variables and reading in data", and then "Reading an external file", you will have the process of the steps you need to follow outlined for you, including links to the help topic for each command you need to issue.
So what I think you need to do is use the DESCRIPTION command to specify the names of your fields, their type, and also their width, in order to ensure no truncation of data on the load.
The same DESCRIPTION statement is required if you want to use your text file as the source of a dimension.
Hope this helps,
Robert -
Reading words from a text file
I have written code to store words in a text file. they appear in the text file as shown below.
word1
word2
word3
etc.
I want to read each word individually and store them in an array. Im trying to do it using a BufferedReader but it doesn't seem to work. The code for reading the words is shown below. Any suggestions would be appreciated.
try
FileReader reader = new FileReader("words.txt");
BufferedReader bReader = new BufferedReader(reader);
ArrayList words = new ArrayList();
String line;
while((line = bReader.readLine()) != null)
line = bReader.readLine();
words.add(line);
bReader.close();
catch (Exception e)
System.err.println ("Error writing to file");
}I think your code is wrong, because it Read two time from file,
your code like....
while((line = bReader.readLine()) != null)
line = bReader.readLine();
words.add(line);
you have to change the above code like
while((line = bReader.readLine()) != null)
words.add(line);
NOW ITS WORKING FINE,........... -
Adding data from a text file into a JTextArea
I'm working on a blogging program and I need to add data from a text file named messages.txt into a JTextArea named messages. How do I go about doing this?
then you need to be more specific in what you need help with because those are two commonly used options for reading data in from a file. what have you tried? where is your code failing? what kind of errors are you getting? of course it looks like others in the forum have already reprimanded you for failing to post properly.
i have used both FileReader and the nio package for cfg and ini files which are both just txt files as well as massive data files. so tell me how they dont help you? -
Replace/cut part of words from a text file.
Hello Hello everyone, I have a quick question. I have my text file that contains also words like ... let's say abc1, abc2 and so on, and I need to cut the c from the word, I need ab1, ab2.
Here is what I have started:
import java.util.*;
import java.io.*;
public class test
Vector<String> x = new Vector<String>();
public mergefiles() throws IOException
readAdd("test.txt");
write("testout.txt");
private void readAdd(String name) throws IOException
BufferedReader reader = new BufferedReader(new FileReader(name));
String line,all=new String();
while ((line = reader.readLine ()) != null)
all+=line+'\n';
reader.close ();
int posX=all.indexOf("X"); // x being like first word of the text file
if (all.length()-posX>0)
String between=all.substring(posX+3,all.length());
StringTokenizer st=new StringTokenizer(between," \n");
private void write(String name) throws IOException
BufferedWriter writer = new BufferedWriter(new FileWriter(name));
String s=new String();
if (x.size()>0)
s+="X"+'\n';
s+='\n';
writer.write(s);
writer.close();
public static void main(String[] args) throws IOException
new test();
}I am new to Java and I would really appreciate if you would be patient with me.
Thank you!I have tried in readAdd method something like:
int posX=all.indexOf("X"); // x being like first word of the text file
if (all.length()-posX>0)
string.replace("ab1","abc1");
} but still doesn't work, and this is not a really good ideea, in case that I have to replace 1000 of abci ...I should use a for in my write method:
String[] s=new String[2];
for(int i=0;i<word.length;i++)
BufferedWriter writer = new BufferedWriter(new FileWriter(testout.substring(0, testout.lastIndexOf("."))+(i+1)+".txt"));
writer.write(s);
writer.close();
But I not really sure if this is ok! Right now nothing is working
Thanks -
Importing data from a text file into a table
Hi Experts,
I have the following flat file
weekly_eft_repo 1.0 Page: 1
CDC:00304 / Sat Oct-31-2009 Weekly EFT Sweep for 25/10/09 - 31/10/09 Effective Date 03/11/09 Sat Oct-31-2009 22:06:14
Bill to
Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount Instant Amount Total Amount
======== ============================== ============================== ========== ==================== =============== =============== ===============
0200101 Triolet Popular Store Triolet Popular Store 111111111 62030100130659 10,868.00 0.00 10,868.00
0200103 Le Cacharel Snack Le Cacharel Snack 111111111 62030100130813 9,728.00 0.00 9,728.00
0200104 Advanced Co-operative Self Ser Advanced Co-operative Self Ser 111111111 111111111 7,334.00 0.00 7,334.00
0200105 Chez Popo Supermarket Chez Popo Supermarket 111111111 61030100044898 30,932.00 0.00 30,932.00
0200106 Vana Supermarket Vana Supermarket 111111111 111111111 17,775.00 0.00 17,775.00
0200107 Mont Choisy Store Mont Choisy Store 111111111 62030100130804 8,840.00 0.00 8,840.00
0200108 Vijay Store Vijay Store 111111111 62030100131229 16,416.00 0.00 16,416.00
0200109 Neptune Confection Neptune Confection 111111111 62030100130931 11,077.00 0.00 11,077.00
0200110 Antoine Store Antoine Store 111111111 111111111 2,470.00 0.00 2,470.00
0200111 P.S.C Cold Storage P.S.C Cold Storage 111111111 111111111 10,431.00 0.00 10,431.00
0200113 Mini Prix Boutique Mini Prix Boutique 111111111 62030100131501 26,315.00 0.00 26,315.00
0200114 Hotel Cassim Hotel Cassim 111111111 111111111 135,147.00 0.00 135,147.00
0200116 Aman Snack Aman Snack 111111111 62030100129481 7,334.00 0.00 7,334.00
0200117 Best For Less Company Ltd Best For Less Company Ltd 111111111 111111111 3,325.00 0.00 3,325.00
0200118 Central Way Central Way 111111111 111111111 25,137.00 0.00 25,137.00I need to insert the data it contains into the following table
TABLE weekly_eft_report_temp
Name Null? Type
BILL_TO_RETAILER NOT NULL VARCHAR2(15)
RETAILER_NAME VARCHAR2(100)
NAME_ON_BANK_ACCOUNT VARCHAR2(100)
BANK_ABA VARCHAR2(1)
BANK_ACCT VARCHAR2(1)
ON_LINE_AMOUNT NUMBER
INSTANT_AMOUNT NUMBER
TOTAL_AMOUNT NUMBER Whats the easiest and best way to proceed on that?
Thanks
KevinI am with Chris on this one.
If those headers are repeating in your text file, you could run a simple script to cleanse the data first and make the file fit for SQL*Loader.
Here's an example with Perl, I hope the header of Page 2 and onwards resembles what you have in your file. I've snipped some data from the far right so that it fits on my terminal screen:
$
$ # show the contents of the data file
$
$ cat report.dat
weekly_eft_repo 1.0 Page: 1
CDC:00304 / Sat Oct-31-2009 Weekly EFT Sweep for 25/10/09 - 31/10/09 Effective Date 03/11/09 Sat Oct-31-2009 22:06:14
Bill to
Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount
======== ============================== ============================== ========== ==================== ===============
0200101 Triolet Popular Store Triolet Popular Store 111111111 62030100130659 10,868.00
0200103 Le Cacharel Snack Le Cacharel Snack 111111111 62030100130813 9,728.00
0200104 Advanced Co-operative Self Ser Advanced Co-operative Self Ser 111111111 111111111 7,334.00
0200105 Chez Popo Supermarket Chez Popo Supermarket 111111111 61030100044898 30,932.00
0200106 Vana Supermarket Vana Supermarket 111111111 111111111 17,775.00
weekly_eft_repo 1.0 Page: 2
CDC:00304 / Sat Oct-31-2009 Weekly EFT Sweep for 25/10/09 - 31/10/09 Effective Date 03/11/09 Sat Oct-31-2009 22:06:14
Bill to
Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount
======== ============================== ============================== ========== ==================== ===============
0200107 Mont Choisy Store Mont Choisy Store 111111111 62030100130804 8,840.00
0200108 Vijay Store Vijay Store 111111111 62030100131229 16,416.00
0200109 Neptune Confection Neptune Confection 111111111 62030100130931 11,077.00
0200110 Antoine Store Antoine Store 111111111 111111111 2,470.00
0200111 P.S.C Cold Storage P.S.C Cold Storage 111111111 111111111 10,431.00
weekly_eft_repo 1.0 Page: 3
CDC:00304 / Sat Oct-31-2009 Weekly EFT Sweep for 25/10/09 - 31/10/09 Effective Date 03/11/09 Sat Oct-31-2009 22:06:14
Bill to
Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount
======== ============================== ============================== ========== ==================== ===============
0200113 Mini Prix Boutique Mini Prix Boutique 111111111 62030100131501 26,315.00
0200114 Hotel Cassim Hotel Cassim 111111111 111111111 135,147.00
0200116 Aman Snack Aman Snack 111111111 62030100129481 7,334.00
0200117 Best For Less Company Ltd Best For Less Company Ltd 111111111 111111111 3,325.00
0200118 Central Way Central Way 111111111 111111111 25,137.00
$
$
$ # snip off the headers using Perl so that the transformed file has just the data to load
$
$ perl -lne 'BEGIN{$/=""} s/^weekly.*?=\n//msg; print' report.dat
0200101 Triolet Popular Store Triolet Popular Store 111111111 62030100130659 10,868.00
0200103 Le Cacharel Snack Le Cacharel Snack 111111111 62030100130813 9,728.00
0200104 Advanced Co-operative Self Ser Advanced Co-operative Self Ser 111111111 111111111 7,334.00
0200105 Chez Popo Supermarket Chez Popo Supermarket 111111111 61030100044898 30,932.00
0200106 Vana Supermarket Vana Supermarket 111111111 111111111 17,775.00
0200107 Mont Choisy Store Mont Choisy Store 111111111 62030100130804 8,840.00
0200108 Vijay Store Vijay Store 111111111 62030100131229 16,416.00
0200109 Neptune Confection Neptune Confection 111111111 62030100130931 11,077.00
0200110 Antoine Store Antoine Store 111111111 111111111 2,470.00
0200111 P.S.C Cold Storage P.S.C Cold Storage 111111111 111111111 10,431.00
0200113 Mini Prix Boutique Mini Prix Boutique 111111111 62030100131501 26,315.00
0200114 Hotel Cassim Hotel Cassim 111111111 111111111 135,147.00
0200116 Aman Snack Aman Snack 111111111 62030100129481 7,334.00
0200117 Best For Less Company Ltd Best For Less Company Ltd 111111111 111111111 3,325.00
0200118 Central Way Central Way 111111111 111111111 25,137.00
$
$ You could do an inline substitution with Perl, or redirect it to a temp file and then move back to the original file. In either case, you have just the relevant data for the next step.
Again, Perl is just one option. On Unix/Linux systems, you have a large number of utilities/scripting languages that can perform almost any kind of data transformation.
HTH,
isotope
Maybe you are looking for
-
Hi is there any excutable to process Session BDC
Hi Friends For sesion we will process with SM35 tcode, is there any exuctable other than this, Regards Jagadeeshwar.B
-
OWB trying to create merge when should be update statement
Hi there Have a problem whereby when set target update type of table to update, OWB trying to create a merge and failing with message merge sttament cannot be generated because column <column_name> is used for both matching and update. A matching col
-
How do I export a menu screen as a jpeg or image file
Hopefully someone can help me out with this...I'm trying to take a menu screen that I've built in DVDSP 4 and export it as a still image so I can use it as a picture to place on the box for my dvd. Any suggestions on how to do this? I haven't been ab
-
Connect search help to standard table
hi! i want to connect search help to structure P0001-MSTBR, without a repair. is it possible? and if so how? regards yifat
-
Best coding language for dynamic dropdown with prices
Any good references for starting points in PHP?