Loading a text file on startup into a hashtable
I am trying to load to seperate textfiles into the same hashtable.
The textfiles are something like an employee and employee number everything goes in at the same time. How do i load these text files into the hashtable. Also any good tutorials or code samples on hashtables would be greatly appreciated.
Thanks In Advance
You read the text files, one line at a time, and break up each line in whatever way you need to. Then you choose the bits to put in the hashtable (key and value) for each line and put those bits into the hashtable.
http://java.sun.com/docs/books/tutorial/essential/index.html
http://java.sun.com/docs/books/tutorial/collections/index.html
Similar Messages
-
How can I use sql loader to load a text file into a table
Hi, I need to load a text file that has records on lines tab delimited into a table. How would I be able to use the sql loader to do this? I am using korn shell to do this. I am very new at this...so any kind of helpful examples or documentation would be very appreciated. I would love to see some examples to help me understand if possible. I need help! Thanks alot!
You should check out the documentation on SQL*Loader in the online Oracle document titled Utilities. Here's a link to the 9iR2 version of it: http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/part2.htm#436160
Hope this helps. -
Cant get data from text file to print into Jtable
Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
String hold;
try {
File f = new File("customer.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
Vector dataVector = new Vector();
Vector headVector = new Vector(2);
Vector row = new Vector();
// read the record of the text database
while ( (dbRecord = dis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbRecord, ",");
while (st.hasMoreTokens()) {
row.addElement(st.nextToken());
System.out.println("Inside nested loop: " + row);
System.out.println("inside loop: " + row);
dataVector.addElement(row);
System.out.println("outside loop: " + row);
headVector.addElement("Title");
headVector.addElement("Type");
dataTable = new JTable(dataVector, headVector);
dataTableScrollPane.setViewportView(dataTable);
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error!" + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
} // end if
} // end finally
} // end dbTestHere's a thread that loads a text file into a JTable:
http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
And my reply in this thread shows how you can use a text file as a simple database:
http://forum.java.sun.com/thread.jsp?forum=31&thread=342380 -
How to load a text file?
I'm trying to load a text file and I've run into a wall. So
far, I've loaded swf files, image files and XML files without
problems. But the text files just don't seem to load.
It's not a tough situation. The files are in the same
directory as the application. When I run it, I see no sign that the
file has loaded, but haven't found the error trapping to tell me
what is (not) going on.
The code below was culled from examples on the web, they seem
fairly consistent, and they are copied pretty much exactly. and I
put them both into a single action to test them.
Any clues as to what is not happening? I need to read an old
txt data file that was used with AS2, with pairs of names and
variables. The first example just reads a couple of variables. The
second just reads some random text. I'm just trying to see what
works here, so I can incorporate working code into the real
program.
Thanks for your help.Thanks Joergen,
I put in the changes you suggested and still no sign that the
files are even being opened., but it's very good to have the
feedback. Just the fact that someone is getting them to run gives
me confidence in the basic code. I'll hack on it more and let you
know what the answer turns out to be for me.
Thanks. -
How to load a text file int JEditorPane and highlight some words (Urgent !)
I want to load a text file into a JEditorPane and then highlights some keywords such as while,if and else.I am using an EditorKit in order to style the JEditorPane. I have no difficulty while giving the input through the keyboard but lots of exceptions are thrown if i try to load the string from a file.
Hi,
I think the setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace) will solve the problem.
You can create your own Styled Document and set it to the Editor Pane. -
Loading a text file to a buffer
Hi,
I have a very simple question,
I have a text file which I want to read and load it in a string buffer, but I don't want to user BufferedReader and append line by line,
is it possible to load the text file into StringBuffer without any loops / appends?
Thanks,
S.File file = new File("fileName.fileExtension");
byte[] c = new char[file.length()];
FileReader reader = new FileReader(file);
try{
reader.read(c);
}catch(IOException e) { System.out.println("An error has ocurred");}
String makeMeString = new String(c);
Stringbuffer buff = new StringBuffer(makeMeString); -
Loading a text file from a relative location in shockwave
Hi all
I'm REALLY sorry I have to post about such an inane problem.
I've googled this and looked in forums and found several
suggestions but none of them are working for me. I want to load a
text file from the same directory as my movie. I can get this
working in authoring mode, in a projector, and in a shockwave movie
on the local machine (using getNetText("/text.txt")).
But when i put the shockwave movie on a server, it does NOT
work. The macromedia documentation says that getNetText works with
relative URLs. But when I put in the full URL, it does work, so
obviously the shockwave movie is having a problem finding the text
file which IS in the same directory as it.
Any suggestions / ideas? All i want to do is access a text
file :)
Sorry again for such a lame problem
Mikethanks - this worked. I also had to not use a repeat loop to
wait for netDone() to return true.
Thanks again
MIke -
Error loading a text file during creation of data load rule
Hi,
I am trying to load this text file but whenever I open File -> Open Data File and then click on the file, it says "Invalid Blank Character in name". I tried changing the name of the file and everything but I do not understand what it really means. Can anyone help me out please? This seems like a simple error but I am unable to figure it out. Thanks.
-- AdiAs Glenn said, there should not be any space in the path that causes the error.For instance if you have ur file in the desktop(C:\Documents and Settings\Desktop), there would be space in between Documents and Settings. To avoid this, you could directly save in your local disk drive(C:\, D:, E:\).
Regards
Cnee -
Loading a text file in a gzip or zip archive using an applet to a String
How do I load a text file in a gzip or zip archive using an applet to a String, not a byte array? Give me both gzip and zip examples.
This doesn't work:
try
java.net.URL url = new java.net.URL(getCodeBase() + filename);
inputStream = new java.io.BufferedInputStream(url.openStream());
if (filename.toLowerCase().endsWith(".txt.gz"))
inputStream = (java.io.InputStream)(new java.util.zip.GZIPInputStream(inputStream));
else if (filename.toLowerCase().endsWith(".zip"))
java.util.zip.ZipInputStream zipInputStream = new java.util.zip.ZipInputStream(inputStream);
java.util.zip.ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null && (zipEntry.isDirectory() || !zipEntry.getName().toLowerCase().endsWith(".txt")))
zipEntry = zipInputStream.getNextEntry();
if (zipEntry == null)
zipInputStream.close();
inputStream.close();
return "";
inputStream = zipInputStream;
else
byte bytes[] = new byte[10000000];
byte s;
int i = 0;
while (((s = inputStream.read())) != null)
bytes[i++] = s;
inputStream.close();
catch (Exception e)
} -
"how to load a text file to oracle table"
hi to all
can anybody help me "how to load a text file to oracle table", this is first time i am doing, plz give me steps.
Regards
MKhaleelUsage: SQLLOAD keyword=value [,keyword=value,...]
Valid Keywords:
userid -- ORACLE username/password
control -- Control file name
log -- Log file name
bad -- Bad file name
data -- Data file name
discard -- Discard file name
discardmax -- Number of discards to allow (Default all)
skip -- Number of logical records to skip (Default 0)
load -- Number of logical records to load (Default all)
errors -- Number of errors to allow (Default 50)
rows -- Number of rows in conventional path bind array or between direct path data saves (Default: Conventional path 64, Direct path all)
bindsize -- Size of conventional path bind array in bytes (Default 256000)
silent -- Suppress messages during run (header, feedback, errors, discards, partitions)
direct -- use direct path (Default FALSE)
parfile -- parameter file: name of file that contains parameter specifications
parallel -- do parallel load (Default FALSE)
file -- File to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions (Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued (Default FALSE)
readsize -- Size of Read buffer (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE
(Default NOT_USED)
columnarrayrows -- Number of rows for direct path column array (Default 5000)
streamsize -- Size of direct path stream buffer in bytes (Default 256000)
multithreading -- use multithreading in direct path
resumable -- enable or disable resumable for current session (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
PLEASE NOTE: Command-line parameters may be specified either by position or by keywords. An example of the former case is 'sqlldr scott/tiger foo'; an example of the latter is 'sqlldr control=foo userid=scott/tiger'. One may specify parameters by position before but not after parameters specified by keywords. For example, 'sqlldr scott/tiger control=foo logfile=log' is allowed, but 'sqlldr scott/tiger control=foo log' is not, even though the position of the parameter 'log' is correct.
SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\PFS2004.CTL LOG=D:\PFS2004.LOG BAD=D:\PFS2004.BAD DATA=D:\PFS2004.CSV
SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\CLAB2004.CTL LOG=D:\CLAB2004.LOG BAD=D:\CLAB2004.BAD DATA=D:\CLAB2004.CSV
SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CTL LOG=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.LOG BAD=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.BAD DATA=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CSV -
When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators. Excel allows you to do this during the import.. Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.
Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
(I don't have an iPad, so I don't know the iOS answer.) -
Pool data from text file and insert into database
Can anyone tell me how to pool data from a text file and insert into database?
let's say my text file is in this format
123456 Peter 22
234567 Nicholas 24
345678 Jane 20
Then I need to insert the all the value for this three column into a table which has the three column name ID, Name, Age
Anyone knows? I need to do this urgently...Thank in advanced1. Use BufferedReader and read the file line by line.
2. Loop thru the file and do the following steps with in this loop.
3. Use StringTokenizer to seperate each line into three values (columns).
4. Now create a insert statement with these values and add the statement to the batch (using addBatch() method of PreparedStatement or Statement).
5. Finally (after exiting the loop), execute these batch of statements (using ps.executeBatch()).
Sudha -
Loading a text file into a global variable issue - really a global var?
From all the documentation and examples I can find, it appears that it would be
correct to create a global array variable [outside of any functions] to load image names into,
then use these images for a slideshow. I want to make the app dynamic, in that changing the text file gives a new set of images.
The global variable goes null [no values] after the load event listener. Why is that?
Isn't global, well global, and alive for the duration of the SWF?
PARAMS.TXT:
monthNames=January,February,March,April,May,June,July,August,September,October,November,De cember&dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
CODE:
var dNames:Array = new Array();
var mNames:Array = new Array();
var request:URLRequest = new URLRequest("images/params.txt");
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event.COMPLETE, completeHandler);
try
variables.load(request);
catch (error:Error)
trace("Unable to load URL: " + error);
trace("2 mNames 2: " + mNames[2]);
trace("2 dNames 3: " + dNames[3]);
stop();
function completeHandler(event:Event):void
var loader:URLLoader = URLLoader(event.target);
dNames = loader.data.dayNames.split(",");
mNames = loader.data.monthNames.split(",");
trace(loader.data.dayNames);
trace("1 mNames 2: " + mNames[2]);
trace("1 dNames 3: " + dNames[3]);
OUTPUT:
2 mNames 2: undefined
2 dNames 3: undefined
Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
1 mNames 2: March
1 dNames 3: Wednesday
How do I access these values after loading from the external file, after the load?
Thanks in advance.The statement you quoted from whatever Adobe documentation is correct.
If you want to load the data into the arrays before anything else happens, then have anything else that happens execute via the completeHandler function... after the data is loaded and processed into the arrays.
the command: loadFile() executes before the trace("2:" +images[4]); command. The loadFile function is processed and the loading process BEGINS... but starting the loading does not delay the main processing from continuing down the line--the loading itself becomes a secondary/background task. The command was to execute the loadFile function and the processing of that function was completed. If you don't believe so, then add a trace...
function loadFile():void
vars.dataFormat = URLLoaderDataFormat.VARIABLES;
vars.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
vars.load(new URLRequest("images/fnames.txt"));
trace("started loading");
If you add that trace, you should see that the loadFile function execution is completed and the next line in your code is then processed... trace(2....)
The addEventlistener does not stop anything. The addEventListener code is assigning a monitor, not a traffic controller... it is telling the monitor to indicate when the data has finished loading. It is not telling anything to stop program execution.
So if you want to wait until the data is loaded before you do anything else... it goes....
function onComplete(evt:Event):void
var urlVars:URLVariables = evt.target.data;
images = vars.data.images.split(",");
tnails = vars.data.thumbnails.split(",");
................HERE................. -
How to load a text file (ASCII) into a TS string variable?
I need to load a ASCII file into a TS string variable for subsequent processing. I tried the SecuenceBuilder DLL (in the examples directory) but it seems that this DLL has a bug. Some text files are not loaded properly. I have also tried the kernel32 functions (openfile, createfile, readfile ... ) handling them as a C program, but with no success. The property loader feature of TS is not the suitable solution for me, because I would have to modify all my text files to include some specific fields (step name, variables, starmarker ...). Doy you know an alternative procedure to load text files or any DLL that implements what I look for ? Any help would be grateful. Cesar ([email protected])
Hi Cesar,
I don't know if you have found a solution, but attached is a DLL built in VC that will read the text out of a file into a TestStand variable. The attached sequence file \SequenceFile1.seq contains a step type that is set to call the DLL responsible for reading the file. It reads the file specified under Step.FilePath and stores the data in Step.ReadData. Please let me know if this works for you. I have attached the source as well.
Regards,
Bob
Attachments:
ReadFile.zip 3628 KB -
Loading a text file into Terminal App
Hi,
I am trying to load a textfile into my Terminal App using the Import utility under the Shell drop down menu.
But when I try choosing the text files after clicking Import, I am unable to select a text file because they are
all greyed out. Only folders seems to be selectable.
Please help.I have no idea what you are trying to do. What does "load a textfile" mean?
The Import… command is for importing a Terminal settings file (exported using the Export Settings… command on another computer or user).
Maybe you are looking for
-
BRS issue while posting in ff67
Hi experts I done brs changes in my server, that one i implemented in client server. While testing in client server t code ff67. checking in feba its not posted, the error system showing "give movement typ x1 to x50". This is nothing but transaction
-
Cyrillic fonts in Story?
Dear Adobe, could you please install Cyrillic fonts? I can not neither name project in Russian, nor write a line in script.
-
Hi, I have an ear file which has ejb jar and war file. Application is running fine through Jdeveloper but when am trying to deploy it in Oracle Application Server 10g getting following error. Any help in this would be appreciated. Deployment failed:
-
How to deal with multiple mail files?
Here's the story; it's sad but true: After a failed iSync spirited away all of my emails, the Apple Care techie I spoke to a month ago wasn't able to fully resolve the problem. So, currently in my Home Library folder I have 2 Mail files: #1 is labele
-
I used davinci lite resolve to color edit my footage then I exported round trip to Final cut pro (premiere). Then exported out of premiere and it doesn't look the same at all. What can I do to fix this problem? I have exported from davinci in 10 bit