Problem – loading HTMLtext from a text file
Problem – loading HTMLtext from a text file
Hi, I have a dynamic text set up to render text as HTML and I
am loading the text into the text object by using the code below.
var loadText:LoadVars = new LoadVars();
loadText.load("Nyheter.txt");
loadText.onLoad = function(success){
if(success){
Nyheter_txt.htmlText = this.VariabelTekst;
The textfile looks like:
VariabelTekst=<p align
="Right">(13.11.2006)</p><p><b><font
size="12">This is the tittle</b></p><p>Here
comes the text</p>
It works almost fine but the first problem is that the
paragraph text in the textfile should be written in Norwegian. This
involves some Nordic characters. By default these characters are
just shown as small square in the text control when running the
flash file. If I try to enter these characters in the textbox
“Include these characters” within the dialog for
embedding, the text within the bold tag of the text file is not
shown when the text is rendered. It looks as if it effect the HTML
rendering of the text. The Nordic characters are still not showing
but instead the small square placeholders for the characters are
gone.
Am I doing it wrong, or is there a work around for solving
this problem?
Any ideas?
TIRislaa
Problem – loading HTMLtext from a text file
Hi, I have a dynamic text set up to render text as HTML and I
am loading the text into the text object by using the code below.
var loadText:LoadVars = new LoadVars();
loadText.load("Nyheter.txt");
loadText.onLoad = function(success){
if(success){
Nyheter_txt.htmlText = this.VariabelTekst;
The textfile looks like:
VariabelTekst=<p align
="Right">(13.11.2006)</p><p><b><font
size="12">This is the tittle</b></p><p>Here
comes the text</p>
It works almost fine but the first problem is that the
paragraph text in the textfile should be written in Norwegian. This
involves some Nordic characters. By default these characters are
just shown as small square in the text control when running the
flash file. If I try to enter these characters in the textbox
“Include these characters” within the dialog for
embedding, the text within the bold tag of the text file is not
shown when the text is rendered. It looks as if it effect the HTML
rendering of the text. The Nordic characters are still not showing
but instead the small square placeholders for the characters are
gone.
Am I doing it wrong, or is there a work around for solving
this problem?
Any ideas?
TIRislaa
Similar Messages
-
PROBLEM LOADING DATA FROM A TEXT FILE.
Hi,
Im having a problem in loading my csv file to the database. Im using Oracle Database 10g for Linux. Im in p. 228 in the book. This is my csv file look.
db_name db_version host_id
db10 9.2.0.7 1
db11 10.2.0.1 1
db12 10.2.0.1 1
db13 9.2.0.7 1
db14 10.2.0.1 1
db15 9.2.0.7 1
I loaded this data to an existing table called DATABASES loaded from tab delimited. FILE CHARACTER SET is UNICODE UTF-8. Then I browsed the name of the csv file to be uploaded. It looked like this.
File Name F23757437/db2.csv Reupload File
Separator
Optionally Enclosed By
First row contains column names.
File Character Set
I CLICKED NEXT, THIS IS WHAT IT LOOKED LIKE.
Schema: HANDSONXE06
Table Name: DATABASES
Define Column Mapping
Column Names %
Format
Upload yes
Row 1 "db10" "9.2.0.7" 1
Row 2 "db11" "10.2.0.1" 1
Row 3 "db12" "10.2.0.1" 1
Row 4 "db13" "9.2.0.7" 1
Row 5 "db14" "10.2.0.1" 1
Row 6 "db15" "9.2.0.7" 1
I CLICKED LOAD AND THIS WAS THE RESULT.
* There are NOT NULL columns in HANDSONXE06.DATABASES. Select to upload the data without an error.
Schema
Down
Table Name
Down
File Details
Down
Column Mapping
Load Data
Schema: HANDSONXE06
Table Name: DATABASES
Define Column Mapping
Column Names COLUMN_NAMES
Format FORMAT
Upload UPLOAD
Row 1 "db10" "9.2.0.7" 1
Row 2 "db11" "10.2.0.1" 1
Row 3 "db12" "10.2.0.1" 1
Row 4 "db13" "9.2.0.7" 1
Row 5 "db14" "10.2.0.1" 1
Row 6 "db15" "9.2.0.7" 1
I WAS REALLY WONDERING WHAT WAS REALLY WRONG. AN ERROR MESSAGE SAID, THERE ARE NOT NULL COLUMNS IN THE HANDSONXE06.DATABASES. I DIDN'T KNOW HOW TO FIX IT. WHAT DO I NEED TO CHANGE TO LOAD THE DATA WITHOUT AN ERROR? IT REALLY CONFUSED ME A LOT AND HOW COME I HAVE AN ERROR? PLEASE HELP ME. I NEED AND ANSWER TO MY PROBLEM PLEASE. I CANNOT GO FORWARD BECAUSE OF THIS.
THANKS,
JOCELYNI'm not certain of the utility you are using to load the data, however, I completed the following test using SQL Loader to insert the data into my table. Your process should work similar if the trigger and sequence are created for the table you are loading.
SQL> create table load_tbl
2 (db_id number(3) not null,
3 db_name varchar2(100) not null,
4 db_version varchar2(25),
5 host_id number(3) not null)
6 /
Table created.
SQL> desc load_tbl
Name Null? Type
DB_ID NOT NULL NUMBER(3)
DB_NAME NOT NULL VARCHAR2(100)
DB_VERSION VARCHAR2(25)
HOST_ID NOT NULL NUMBER(3)
SQL> create sequence db_id_seq;
Sequence created.
SQL> create or replace trigger db_id_trig
2 before insert on load_tbl
3 for each row
4 when (new.db_id is null)
5 begin
6 select db_id_seq.nextval into :new.db_id from dual;
7 end;
8 /
Trigger created.
The contents of the data file, control file and log file are below for the load into load_tbl.
C:\>sqlldr userid=username/password@db control=db_id_load.ctl log=db_id_load.log
SQL*Loader: Release 9.2.0.6.0 - Production on Thu Jan 18 17:21:47 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Commit point reached - logical record count 6
C:\>
SQL> select * from load_tbl
2 /
DB_ID DB_NAME DB_VERSION HOST_ID
1 db10 9.2.0.7 1
2 db11 10.2.0.1 1
3 db12 10.2.0.1 1
4 db13 9.2.0.7 1
5 db14 10.2.0.1 1
6 db15 9.2.0.7 1
6 rows selected.
SQL>
Data File"db10" "9.2.0.7" 1
"db11" "10.2.0.1" 1
"db12" "10.2.0.1" 1
"db13" "9.2.0.7" 1
"db14" "10.2.0.1" 1
"db15" "9.2.0.7" 1
Control FileLOAD DATA
INFILE "C:\db_id_load.dat"
APPEND INTO TABLE load_tbl
FIELDS TERMINATED BY WHITESPACE OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(db_name CHAR,
db_version CHAR,
host_id "TO_NUMBER(:host_id,'99999999999')"
Log FileSQL*Loader: Release 9.2.0.6.0 - Production on Thu Jan 18 17:21:47 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Control File: db_id_load.ctl
Data File: C:\db_id_load.dat
Bad File: db_id_load.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table LOAD_TBL, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
DB_NAME FIRST * WHT O(") CHARACTER
DB_VERSION NEXT * WHT O(") CHARACTER
HOST_ID NEXT * WHT O(") CHARACTER
SQL string for column : "TO_NUMBER(:host_id,'99999999999')"
Table LOAD_TBL:
6 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 49536 bytes(64 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 6
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Thu Jan 18 17:21:47 2007
Run ended on Thu Jan 18 17:21:47 2007
Elapsed time was: 00:00:00.39
CPU time was: 00:00:00.13 -
Error while loading data from a text file to a datastore
Hi all,
i am a starter in ODI. I am trying to load data from a text file into a datastore. I have put the file on a unix server whose location is defined in the topology manager. when i am trying to "view data" it is giving me error file does not exist at <location where i have put the file>. Please help meHi,
1. If your files are on a remote File System, you will need to copy one of your files to the machine ODI Designer is running on to allow ODI to retrieve the metadata information of the file.
2. In Topology create a Physical Schema, the directory you enter for Data and Work Schema should point at this local file.
3. Then define the File Datastore in ODI Designer. Enter a name, browse and select the file and fill in each filed of the Files tab.
* If its a Fixed file, click on the grid icon on the Columns tab to enter the columns and have Automatic Adjustment checked.
* If its a Delimited file, use the Reverse button on the Columns tab to reverse the columns.
* Right click on the File Datastore select View Data, if you can view data, that means the File Datastore has been defined correctly.
* If not, check each tab of the File Datastore to make sure everything is defined correctly and retry.
4. Once View Data is successful, you now change the directories (Data and Work Schema in Topology) to point at the remote File System. These directories must be accessible to the ODI Agent that will be used to run the transformations. The directory can be an absolute path (m:/public/data/files) or relative to the ODI Agent startup directory (../demo/files). It is strongly advised to use a UNC (independent from the execution location) for the path. When running the transformations with "no agent", the directory is relative to the directory where Oracle Data Integrator has been installed.
You need to have a agent process running at the system where your source file resides .
Then while running the odi interface choose that agent .
Thanks,
Sutirtha -
I have a text file in a data archive that contains various information (numeric and string) that I need to load into different controls in a VI would I have to open the file and look for certain characters to begin and end loading? The information was previously stored by the VI from the control so can I simply load a previous set of data by using it's data path and control file name?
Solved!
Go to Solution.I assume that the numbers following the "OH data is listed below:" is supposed to go into a 2D array?
There are several ways to do this. One simple way is to simply read the file and chop off each section of interest, and converting the string to a 2D array, like this:
Another is to read the file in using the Read From Spreadsheet File, and then indexing out the first column, and use that to search for the indices where the regions of interest lie. You can then use Array Subset to get the 2D array of data.
Message Edited by smercurio_fc on 07-22-2009 02:56 PM
Attachments:
Example_VI.png 15 KB -
Is there away to load data from a text file to a table?
I have data stored in filename.txt and I want to load those data into a table on the front pannel of vi. How can I do that?
Se;
If the text file is already in an spreadsheet format, you can download the VI Read Strings From Spreadsheet File from my website:
http://www.jyestudio.com/lview.shtml
It is the suggested modification of the VI Read From Spreadsheet File that comes with LabVIEW, as stated in the diagram.
If the text file is not in spreadsheet format, then you need to write your own code to make the string table suitable for the table.
Regards;
Enrique
www.vartortech.com -
How to automate loading data from a text file ?
Hi,
I need to load a data form a text file automatically. (for example: every day at 6.p.m) .
It is possible to use DBMS_SCHEDULER with SQL LOADER ? or maybe u have others idea ?
regards,assuming that the text file resides at the machine where the database is installed at you can create a procedure that use the built-in UTL_FILE package to read and load the data to the oracle tables. then create a job that use the DBMS_JOB or DBMS_SCHEDULER to create an automated schedule to run the job that calls the procedure you have created.
or assuming that the text file resides or at the local/client machine (example c:\ drive) on a windows xp platform. create a batch file that do a ftp to transfer the text file to the oracle database server and create a schedule job using the windows scheduler. also create a procedure that use the built-in UTL_FILE package to read and load the data to the oracle tables. then create a job that use the DBMS_JOB or DBMS_SCHEDULER to create an automated schedule to run the job that calls the procedure you have created. -
Loading Data From a Text File Through an Application into Oracle
Hi There,
I have a web application that allows the user to upload a text file. This file is then processed by my application. Each line in the file is a new row I need to insert into my table.
Currently, I batch 200 updates together and insert them into the DB.
For about 3 million records this is taking much longer than I would like it to.
Any suggestions for optimization?
thanks.I put here a simplest demo (file has whitespace)
I think it may help to start.
--Structure of your file test1.dat (put in your directory)
a1 b1
a2 b2
a3 b3
a4 b4
CREATE OR REPLACE DIRECTORY
test_dir AS
'C:\oraclexe\DIR' --or anywhere
--GRANT READ, WRITE ON DIRECTORY test_dir TO your_user
--external table:
DROP TABLE test_ext
CREATE TABLE test_ext
(col1 CHAR(5),
col2 CHAR(5)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY test_dir
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY WHITESPACE)
LOCATION ('test1.dat')
SELECT * FROM test_ext
COL1 COL2
a1 b1
a2 b2
a3 b3
a4 b4
Insert into another_table(another_col1, another_col2) (select col1, col2 from test_ext) if needed -
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 -
How to load Test data from a Text file in ECATT
Hi,
I have created a test configuration with a test script, system data container, and test data container.
I have done the recording of a transaction and created the script. Parameterization is done for the script and have imported those parameters from script in to the data container.
I am trying to load a the data from a text file on the local work-station. The data is not being read.
Please explain this in detail (step by step) as I am very new to ECATT.
I am trying this on SAP ECC 6.0 IDES server.
Thanks in Advance
Vikas PatilPlease explain this in detail (step by step) as I am very new to ECATT.
Thanks in Advance
Vikas Patil -
How to load SQL scripts from a text file.
Hi, i tried several time to load a text file/SQL script with 10 different tables and data, but 10g Express doesen't allows me to do that, any one can direct me or point out to me what i should do or do i need to adopt any special method to to get this done. i am sure there must be some thing where you can upload SQL scripts from a text file (in SQL command editor!). thanks
Hi,
see my other answer here:
SQL command editor doesn't take more than 1 insert command
This seems to be a duplicate question, right? Or am I missing something?
Regards,
~Dietmar. -
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 -
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 a Random Line from a Text File
Hello,
I have a program that reads from a text file words. I currently have a text file around 800KB of words. The problem is, if I try to load this into an arraylist so I can use it in my application, it takes wayy long to load. I was wondering if there was a way to just read a random line from the text file.
Here is my code, and the text file that the program reads from is called 'wordFile'
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class WordColor extends JFrame{
public WordColor(){
super("WordColor");
setSize(1000,500);
setVisible(true);
add(new WordPanel());
public static void main(String[]r){
JFrame f = new WordColor();
class WordPanel extends JPanel implements KeyListener{
private Graphics2D pane;
private Image img;
private char[]characterList;
private CharacterPosition[]positions;
private int charcounter = 0;
private String initialWord;
private File wordFile = new File("C:\\Documents and Settings\\My Documents\\Java\\projects\\WordColorWords.txt");
private FontMetrics fm;
private javax.swing.Timer timer;
public final static int START = 20;
public final static int delay = 10;
public final static int BOTTOMLINE = 375;
public final static int buffer = 15;
public final static int distance = 4;
public final static Color[] colors = new Color[]{Color.red,Color.blue,Color.green,Color.yellow,Color.cyan,
Color.magenta,Color.orange,Color.pink};
public static String[] words;
public static int descent;
public static int YAXIS = 75;
public static int SIZE = 72;
public WordPanel(){
words = readWords();
setLayout(new BorderLayout());
initialWord = getWord();
characterList = new char[initialWord.length()];
for (int i=0; i<initialWord.length();i++){
characterList[i] = initialWord.charAt(i);
setFocusable(true);
addKeyListener(this);
timer = new javax.swing.Timer(delay,new ActionListener(){
public void actionPerformed(ActionEvent evt){
YAXIS += 1;
drawWords();
if (YAXIS + descent - buffer >= BOTTOMLINE) lose();
if (allColorsOn()) win();
public void paintComponent(Graphics g){
super.paintComponent(g);
if (img == null){
img = createImage(getWidth(),getHeight());
pane = (Graphics2D)img.getGraphics();
pane.setColor(Color.white);
pane.fillRect(0,0,getWidth(),getHeight());
pane.setFont(new Font("Arial",Font.BOLD,SIZE));
pane.setColor(Color.black);
drawThickLine(pane,getWidth(),5);
fm = g.getFontMetrics(new Font("Arial",Font.BOLD,SIZE));
descent = fm.getDescent();
distributePositions();
drawWords();
timer.start();
g.drawImage(img,0,0,this);
private void distributePositions(){
int xaxis = START;
positions = new CharacterPosition[characterList.length];
int counter = 0;
for (char c: characterList){
CharacterPosition cp = new CharacterPosition(c,xaxis, Color.black);
positions[counter] = cp;
counter++;
xaxis += fm.charWidth(c)+distance;
private void drawThickLine(Graphics2D pane, int width, int thickness){
pane.setColor(Color.black);
for (int j = BOTTOMLINE;j<BOTTOMLINE+1+thickness;j++){
pane.drawLine(0,j,width,j);
private void drawWords(){
pane.setColor(Color.white);
pane.fillRect(0,0,getWidth(),getHeight());
drawThickLine(pane,getWidth(),5);
for (CharacterPosition cp: positions){
int x = cp.getX();
char print = cp.getChar();
pane.setColor(cp.getColor());
pane.drawString(""+print,x,YAXIS);
repaint();
private boolean allColorsOn(){
for (CharacterPosition cp: positions){
if (cp.getColor() == Color.black) return false;
return true;
private Color randomColor(){
int rand = (int)(Math.random()*colors.length);
return colors[rand];
private void restart(){
charcounter = 0;
for (CharacterPosition cp: positions){
cp.setColor(Color.black);
private void win(){
timer.stop();
newWord();
private void newWord(){
pane.setColor(Color.white);
pane.fillRect(0,0,getWidth(),getHeight());
repaint();
drawThickLine(pane,getWidth(),5);
YAXIS = 75;
initialWord = getWord();
characterList = new char[initialWord.length()];
for (int i=0; i<initialWord.length();i++){
characterList[i] = initialWord.charAt(i);
distributePositions();
charcounter = 0;
drawWords();
timer.start();
private void lose(){
timer.stop();
pane.setColor(Color.white);
pane.fillRect(0,0,getWidth(),getHeight());
pane.setColor(Color.red);
pane.drawString("Sorry, You Lose!",50,150);
repaint();
removeKeyListener(this);
final JPanel p1 = new JPanel();
JButton again = new JButton("Play Again?");
p1.add(again);
add(p1,"South");
p1.setBackground(Color.white);
validate();
again.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
remove(p1);
addKeyListener(WordPanel.this);
newWord();
private String getWord(){
int rand = (int)(Math.random()*words.length);
return words[rand];
private String[] readWords(){
ArrayList<String> arr = new ArrayList<String>();
try{
BufferedReader buff = new BufferedReader(new FileReader(wordFile));
try{
String line = null;
while (( line = buff.readLine()) != null){
line = line.toUpperCase();
arr.add(line);
finally{
buff.close();
catch(Exception e){e.printStackTrace();}
Object[] objects = arr.toArray();
String[] words = new String[objects.length];
int count = 0;
for (Object o: objects){
words[count] = (String)o;
count++;
return words;
public void keyPressed(KeyEvent evt){
char tempchar = evt.getKeyChar();
String character = ""+tempchar;
if (character.equalsIgnoreCase(""+positions[charcounter].getChar())){
positions[charcounter].setColor(randomColor());
charcounter++;
else if (evt.isShiftDown()){
evt.consume();
else{
restart();
drawWords();
public void keyTyped(KeyEvent evt){}
public void keyReleased(KeyEvent evt){}
class CharacterPosition{
private int xaxis;
private char character;
private Color color;
public CharacterPosition(char c, int x, Color col){
xaxis = x;
character = c;
color = col;
public int getX(){
return xaxis;
public char getChar(){
return character;
public Color getColor(){
return color;
public void setColor(Color c){
color = c;
}I thought that maybe serializing the ArrayList might be faster than creating the ArrayList by iterating over each line in the text file. But alas, I was wrong. Here's my code anyway:
class WordList extends ArrayList<String>{
long updated;
WordList readWordList(File file) throws Exception{
WordList list = new WordList();
BufferedReader in = new BufferedReader(new FileReader(file));
String line = null;
while ((line = in.readLine()) != null){
list.add(line);
in.close();
list.updated = file.lastModified();
return list;
WordList wordList;
File datFile = new File("words.dat");
File txtFile = new File("input.txt");
if (datFile.exists()){
ObjectInputStream input = new ObjectInputStream(new FileInputStream(datFile));
wordList = (WordList)input.readObject();
if (wordList.updated < txtFile.lastModified()){
//if the text file has been updated, re-read it
wordList = readWordList(txtFile);
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
output.writeObject(wordList);
output.close();
} else {
//serialized list does not exist--create it
wordList = readWordList(txtFile);
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
output.writeObject(wordList);
output.close();
}The text file contained one random sequence of letters per line. For example:
hwnuu
nhpgaucah
zfbylzt
hwnc
gicgwkhStats:
Text file size: 892K
Serialized file size: 1.1MB
Time to read from text file: 795ms
Time to read from serialized file: 1216ms -
Filling an object ArrayList from a text file
Hi all,
I am developing a project (for university) which has a class named "SupplierAgent", which is required to keep database of custom objects of type "InventoryItem". Basically these consist of a String (for the name of the item), an int representing the quantity on hand, and an int representing the unit price (in cents). I wish to have this inventory loaded from a text file rather than a binary file - that way the user can add new items to the file before loading the agent.
I have included the code below, which works provided the file is rigidly structured. The main problem is the user having to type the path to the file: I cannot guarantee the user will have the file in any folder, and so the user is required to type in the absolute path. Is there any way to make this less annoying? Or is there a better way of loading a preset inventory while allowing the user to edit that inventory at will?
I have included the current code below. it's not exactly in accordance with coding standards, because we are using the JADE agent architecture (hence why the method is called "action") rather than something more informative.
I should also mention that it uses a command line interface. The "io" class basically includes a scanner and the System.out.println method. Its "yesOrNo()" method is for convenience: it asks the user a question and allows them to select y or n.
public void action() {
boolean loadFromFile = io.yesOrNo("Would you like to load the inventory from a file?");
if(loadFromFile) {
BufferedReader br = null;
boolean fileFound = false;
while(!fileFound) {
io.output("Please enter the absolute path to the file, including filename extension: ");
inventoryFile = io.input();
try {
FileReader fr = new FileReader(inventoryFile);
br = new BufferedReader(fr);
fileFound = true;
catch (FileNotFoundException e) {
io.output("File not found. ");
String fileLine = null;
int lineNumber = 1;
InventoryItem item = null;
try {
while((fileLine = br.readLine()) != null) {
switch((lineNumber % 4)) {
case 1: item = new InventoryItem();
item.setName(fileLine); break;
case 2: item.setQuantity(Integer.parseInt(fileLine));
case 3: item.setPrice(Integer.parseInt(fileLine));
case 0: inventory.add(item);
io.output("Inventory loaded successfully\n");
catch(Exception e) {
io.output("Error at line " + lineNumber + " of inventory file\n");
io.output("Unable to fill inventory. Please ensure file is structured correctly\n");
io.output("See readme for explanation of file structure requirements\n");
myAgent.doDelete();
}Edited by: Swiftslide on Apr 22, 2010 6:34 PMYou can use JFileChooser to allow the user to navigate to the required file.
-
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
Maybe you are looking for
-
How to add multiple test conditions in 'test' attribute expression of xsl:if tag
Hi all, How to add multiple test conditions in 'test' attribute expression of <xsl:if> tag ? I have 2 parameters and I want To skip the massage if this 2 conditions happened I tried to write it : <xsl:when test="($TransferToCompany = 0 and $O
-
Resources to learn Premier Pro CS6
Hi there, Ive ordered Classroom in a Book and Learn by Video DVD set already, but was wondering if there are any other resources you can recommend? Thank you a.mouse
-
Is it possible to RE-CREATE table
is it possible to re-create a table in indesign and insert same data by reading data in another table using plugin.if their is a table with data exist as indesign document,can we create new table by inserting data that was already their in the previ
-
TS1424 hello im from iran,
hello im from iran, app store in my ipad new block download for me.error 1009 please help
-
How to return to position in DB
I have a DW site that has database access. The DB has grown to about 3000 entries. When in the admin menu, I can edit individual records and then click on update. The record is updated, but then the next screen goes back to the top of the database. I