Need to read data from a text file
I need to read data from a text file and create my own hash table out of it. I'm not allowed to use the built in Java class, so how would I go implementing my own reading method and hash table class?
It's not possible to read from a file without using classes from the core API*. You'll have to get clarification from your instructor as to which classes are and are not allowed.
[http://java.sun.com/docs/books/tutorial/essential/io/]
*Unless you write a bunch of JNI code to replicate what the java.io classes are doing.
Similar Messages
-
hey ppl
i have a datagrid in my form.i need to read input(fields..sort of a database) from a text file and display its contents in the datagrid.
how can this be done.. and also after every few seconds reading event should be re executed.. and that the contents of the datagrid will keep changing as per the changes in the file...
please help as this is urgent and important.. if possible please provide me with an example code as i am completely new to flex...
thanks.....It's not possible to read from a file without using classes from the core API*. You'll have to get clarification from your instructor as to which classes are and are not allowed.
[http://java.sun.com/docs/books/tutorial/essential/io/]
*Unless you write a bunch of JNI code to replicate what the java.io classes are doing. -
Read data from a text file, one line at a time.
I need to read data from a text file, and display each line in a String Indicator on Front Panel. It displays each line, but I get Error 4, End Of Line, unless I enter an extra line of data in the file that I don't need. I tried Read From Text File.vi, made by Nat Instr, and it gave the same error.
The Read from Text File.vi reads data from a text file line by line until the user stops the VI manually with the Stop button on the front panel, or until an error (such as "Error 4, End of file") occurs. If an error occurs, the Simple Error Handler.vi pops up a dialog that tells you which error occurred.
The Read from Text File.vi uses a while loop, but if you knew how many lines you wanted to read, you could replace the while loop with a for loop set to read that many lines from the file.
If you need something more dynamic because the number of lines in your files vary, then you could change the code of the Read from Text File.vi to the expect "Error 4, End of file" and handle it appropriately. This would require unbundling the error cluster that comes fro
m the Read File function with the Unbundle By Name function, so that you can expose the individual error "status" and error "code" values stored in the cluster. If the value of the error "code" is 4, then you can change the error "status" from true to false, and you can rebundle the cluster with the Bundle by Name function. Setting the error "status" to false instructs the Simple Error Handler to ignore the error. Otherwise, pass the original error cluster to the Simple Error Handler.vi, so that you can see what the error is.
Of course, if you're not interested in what the errors are, you could just remove the Simple Error Handler.vi, but then you wouldn't see any error messages.
Best of Luck,
Dieter
Dieter Schweiss
Applications Engineer
National Instruments -
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. -
Need to read data from pipe separated file using POJO?
Hi,
I need to read data from pipe separated file using POJO.
There is config.properties file which consists of the
data mapping.
Can you help me with sample code or help?
Regards
Regards
Taton
Edited by: Taton on Mar 7, 2009 4:41 PMIt's not possible to read from a file without using classes from the core API*. You'll have to get clarification from your instructor as to which classes are and are not allowed.
[http://java.sun.com/docs/books/tutorial/essential/io/]
*Unless you write a bunch of JNI code to replicate what the java.io classes are doing. -
Reading Data From A Text File via AppleScript
Here is my question. I have a text file I need to read data from....this is what the text file looks like opened in text editor:
"SLUG
, 06/16/06, APPLE COMPUTER INC , 69x8.50, jondnotin
now what I need to do is get the 69 and the 8.50 as seperate variables...now every file that is going to be read is setup the same with different information but the data type is the same and in the same order. So what syntax do I need to read this file and set thoes two numbers to variables? Thanks!
PowerMac G5, iBook G4, Intel MacMini, PowerMac G3 B&W, iMac DV Blueberry Mac OS X (10.4.7)Hello
You where right for the file structure.
I think that it is a complementary reason to locate the data whithout assuming that it sit in paragraph x or y.
The trailing script get rid of that and allow to grab values from a file containing more than a single entry.
--[SCRIPT]
set leChemin to "Macintosh HD:Users:yvankoenig:Desktop:_testfile.txt"
set {val1, val2} to my decipher(read file leChemin, "APPLE COMPUTER INC , ")
display dialog "" & val1 & return & val2
-- -+-+-+-+-+-+-+-
on decipher(t, d)
set {oTID, AppleScript's text item delimiters, texte} to {AppleScript's text item delimiters, d, t}
set {texte, AppleScript's text item delimiters} to {text item 2 of texte, ","}
set {texte, AppleScript's text item delimiters} to {text item 1 of texte, "x"}
set {v1, v2, AppleScript's text item delimiters} to {text item 1 of texte, text item 2 of texte, oTID}
return {v1, v2}
end decipher
-- -+-+-+-+-+-+-+-
--[/SCRIPT]
Yvan KOENIG (from FRANCE vendredi 8 septembre 2006 20:38:46) -
Reading data from a text file but can't use the data outside of the function.
I am trying to load a variable from data in a text file.
I can read the text file fine but the variable data seems
only to be available with in the function that reads it.
I need to use the variable data outside of the function.
Does anyone have any suggestions to work around this issue?
This is the actionscript code i'm using.
var pathVars= new LoadVars();
pathVars.onLoad=function(ok) {
if(ok)
trace("Loading");
path_var=pathVars.path;
trace("This is within the function "+path_var);
pathVar0="This is within the function... "+path_var;
Yet the path_var is available here fine.
pathVars.load("mypath.txt");
This is where the path_var becomes undefined
trace("This is outside the function... "+path_var);
pathVar1="This is outside the function... "+path_var;
This
is a download link for the FLA zip file
This
is a demo of the script loading the text fileThe external traces are being executed before the file is
loaded. -
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 -
Okay so basically i need to read some text from a file, and display it in a JTextArea. My problem is that when i read the data and display it, its all in one big long line. e.g:
in text file:
Hi
Hi
Hi
Hi
in textarea:
HiHiHiHi
I was wondering if it is possible to use some kind of a method that determines when reading the file if its at the end of a line or not, then create a new line.
this is part of my code:
chooser is a JFileChoose object.
File theFile = new File(chooser.getSelectedFile().getPath());
FileReader reader = new FileReader(theFile);
BufferedReader buffer = new BufferedReader(reader);
String ss;
String aa = "";
while((ss = buffer.readLine()) !=null) {
aa = aa + ss;
text.setText(aa);
reader.close();
//Rest of program continues hereHii , I think this will help you ,,,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
class Test5 extends JFrame
JPanel mainPane;
JButton doTestBtn = new JButton("Press");
JTextArea show = new JTextArea(6,6);
JFileChooser choose = new JFileChooser();
public Test5()
GridLayout gl = new GridLayout(1, 2);
gl.setHgap(10);
gl.setVgap(10);
mainPane = new JPanel();
JPanel side1 = new JPanel();
JPanel side2 = new JPanel();
mainPane.add(side1);
mainPane.add(side2);
side1.add(doTestBtn);
side1.add(show);
doTestBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
doTestBtnAction();
private void doTestBtnAction()
try
int tt = choose.showOpenDialog(Test5.this);
if(tt == JFileChooser.APPROVE_OPTION )
File file = choose.getSelectedFile();
FileReader reader = new FileReader(file);
BufferedReader buffer = new BufferedReader(reader);
String ss;
String aa = "";
while((ss = buffer.readLine()) !=null)
aa = aa + ss;
show.append(aa);
reader.close();
}catch(IOException ex)
private void createGUI()
getContentPane().add(mainPane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,100);
pack();
setVisible(true);
private static void createAndShowGUI()
Test5 rn = new Test5();
rn.createGUI();
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI();
}Thanks ,
sb -
Shell scripts to read data from a text file and to load it into a table
Hi All,
I have a text file consisting of rows and columns as follows,
GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL005675 000001 000000 000000 000000 000000 000000 000001 My requirement is that, i should read the first 3 columns of this file using a shell script and then i have to insert the data into a table consisting of 3 rows in oracle .
the whole application is deployed in unix and that text file comes from mainframe. am working in the unix side of the application and i cant access the data directly from the mainframe. so am required to write a script which reads the data from text file which is placed in certain location and i have to load it to oracle database.
so I can't use SQL * loader.
Please help me something with this...
Thanks in advance.1. Create a dictionary object in Oracle and assign it to the folder where your file resides
2. Write a little procedure which opens the file in the newly created directory object using ULT_FILE and inside the FOR LOOP and do INSERTs to table you want
3. Create a shell script and call that procedure
You can use the post in my Blog for such issues
[Using Oracle UTL_FILE, UTL_SMTP packages and Linux Shell Scripting and Cron utility together|http://kamranagayev.wordpress.com/2009/02/23/using-oracle-utl_file-utl_smtp-packages-and-linux-shell-scripting-and-cron-utility-together-2/]
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com -
Reading data from a text file to the MIDP RMS.
Sorry if this is a bit 2 newbie...
What I want to do is read a data file(ie csv), from windows and write the data into the record store.
My main idea is to store the recordstore files on windows and updated them from the text windows files and autosync the recordstores between windows and my palm...
Is this possible? If so is it a crappy way to do it... would there be a better wayHi Stephen:
Bundle the readme.txt, CSV file etc. with the jar that contains your MIDlet. Pretty clever way to initialize a datastore.
public void startApp() throws MIDletStateChangeException
// retrieve the contents of a resource file
System.out.println("Retrieving the resource file - readme.txt");
System.out.println("--------------------------------------------");
InputStream is = this.getClass().getResourceAsStream("readme.txt");
try {
if ( is != null ) {
int ch;
while ( (ch = is.read()) != -1) {
// print out the contents of the readme file
System.out.print((char) ch);
// or move the char in a byte array for the datastore
// I know you get the picture
is.close();
} catch (IOException e) {
System.out.println(e);
} -
How to read data from a text file
I have saved a text file on my hard drive, and would like to read the file. Once read I would like to copy it to another file. I think I am suppose to use the BufferedReader, and FileReader classes. I am not sure what sequence to follow in order to do this. Could some one give me some feed back on what is needed, and in what sequence to perform this task?
Where do I store my file within my Platform(Eclipe), in order to read or access the file. Whenever I use the declaration below. I get an FileNotFoundException. I understand the code, but am not sure where to store the file, so that the line of code below will recognize it..
FileReader in = new FileReader("data1.txt");
BufferedReader a = new BufferedReader(in); -
Reading data from a text file in to an array
Ok nobody tell me to search forums, read books, point me to the tutorials, i have done all that and still don't get it. so can some one help me write some code. I would like to read text from a file into an array. The array name is VehilcleList. Simplest was possible would be great. I dont want to use redirection, preferably using the filereader and filewriter class i imagine.
Your quick example:import java.io.*;
import java.util.*;
public class TryReadFileToArray {
public static void main(String[] args) {
File file = new File("C:/java/eclipse/workspace/scjp/vehicles.dat");
ArrayList vehicles = (ArrayList) getVehicles(file);
for (Iterator i = vehicles.iterator(); i.hasNext(); ) {
System.out.println(i.next());
public static List getVehicles(File file) {
ArrayList vehicles = new ArrayList();
try {
BufferedReader buf = new BufferedReader(new FileReader(file));
while (buf.ready()) {
String line = buf.readLine();
StringTokenizer tk = new StringTokenizer(line, ",");
ArrayList params = new ArrayList();
while (tk.hasMoreElements()) {
params.add(tk.nextToken());
Vehicle v =
new Vehicle(
(String) params.get(0),
(String) params.get(1),
(String) params.get(2),
Integer.parseInt((String) params.get(3)));
vehicles.add(v);
} catch (IOException ioe) {
System.err.println(ioe);
} catch (NumberFormatException nfe) {
System.err.println("Mileage not in correct format: " + nfe);
return vehicles;
class Vehicle {
// flesh out remaining instance members as needed
private String aMake;
public Vehicle(
String aMake,
String aModel,
String aRegistrationNumber,
int aMileage) {
this.aMake = aMake;
public String toString() {
return aMake;
}Uses the following file (vehicles.dat):Ford,Taurus,105BRQ,55000
Dodge,Neon,907JZH,105000
Ferrari,Testarossa,3ATM3,25412 -
Reading data from a text file into a JTextField
So I am writing a program that will write to and read from a large database. I was hoping to allow a graphical interface for the reading of the data, but I keep getting an error;
Incompatible Types
Found: java.lang.string
Required: javax.swing.JTextField
Now I know that this means the are incompatible (like trying to give an integer variable a string command) but I can't find any documentation on how to change the String into a JTextField format. I've found several references on how to do the reverse, but with my lack of JAVA knowledge I can't seem to get it to work. (Tried things like getText() and the like, but just end up with more errors).
*On a side note, is there an easier way to go about reading a file line by line, with each line going into a seperate JTextField, than;
BufferedReader r;
try {
r = new BufferedReader(new FileReader("C:\\temp\\test.txt"));
while ((thisLine = r.readLine()) != null) {
array[i] = thisLine;
i = i + 1
and then assigning each JTextField it's own array slot?*
Thank you for your help.Try something like this for putting the text in a control:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Junk{
String[] s = {"This is String 1.", "This is String 2.", "This is String 3."};
Junk(){
public void makeIt(){
JFrame j = new JFrame("Forum Junk");
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.setPreferredSize(new Dimension(300, 200));
JTextArea jt = new JTextArea();
p.add(jt);
j.add(p);
jt.setText(s[0]);
jt.append("\n\r"+s[1]);
jt.append("\n\r"+s[2]);
j.pack();
j.setVisible(true);
public static void main(String[] args) {
Junk j = new Junk();
j.makeIt();
}Depending on your design you may be able to do away with your array and append the text directly to the JTextArray after each line is read. -
I want to read a file from my forms using TEXT_IO
read about this items.
M_archsal TEXT_IO.FILE_TYPE ;
line varchar2(3000);
text_io.fopen(:PATH,'R')
text_io.is_open(M_archsal)
text_io.get_line(M_ArchSal,line) ;
text_io.fclose(M_ArchSal) ;
Maybe you are looking for
-
EJB adapter errors are not catched by the composite fault handler
Hi, I got a serious problem in soa suite 11g ps3 that ejb adapter failures are not catched by the soa suite fault framework. for example when I do a persist of an entity on a EJB session bean and I dont provide all required fields I get a rollback er
-
We have Cisco Wireless with ISE (Identity Service Engine) to provide guest access with CWA (central web authentication). The idea is to provide guest access with open authentication, so anyone can connect. Then when the guest trying to browse the int
-
Am I supposed to have to Pair the Magic Mouse evertime?
If I turn the MM off, I have to repair it to my MBP every time I turn the mouse on. Is this right? Also, this new mouse doesn't sit flat on the table, it slightly rocks, so the runners on the bottom are not even. I just got this today, and it may b
-
Hi, I am trying to setup Introscope Agent. I have installed it with Software Deployment Manager with no issues and setting up the agent using Diagnostic Agent Setup -> Managed System -> Introscope Agent. I am getting this error. Please suggest on thi
-
I just updated to the most recent version of Pages. now I can't view or access any of the documents created in the previous version. Where did they go? How can I retrieve them?