Reading a text file and transferring values into array
Hi,
I have a problem. So what I am trying to do is that, I read a text file and insert specific values from the text file into an array for future needs.
But I have to make sure that there is no duplicate entries. So thats what I have but, my method takes forever to finish...
here is my code:
String nomFichier = "Test_" + numTest + "_" + date + ".txt";
String ligne = "";
int z = 0;
int j = 0;
BufferedReader lecteurFichier = new BufferedReader(new FileReader(nomFichier));
while ((ligne = lecteurFichier.readLine()) != null) {
if (z > 3)
String valeur = "";
String dist = "";
boolean unique = true;
String [] chiffre = ligne.split(";");
if (intervalleAnalyser == 1)
valeur = chiffre[3];
dist = chiffre[4];
if (intervalleAnalyser == 2)
valeur = chiffre[2];
dist = chiffre[4];
if (intervalleAnalyser == 3)
valeur = chiffre[1];
dist = chiffre[4];
if (z == 4) {
intervalleDiagramme[j] = valeur;
j++;
if (z > 4) {
for (int i = 0; i < intervalleDiagramme.length; i++)
for (int x = 0; x < i; x++)
if(intervalleDiagramme[i] == intervalleDiagramme[x])
unique = false;
if (unique)
intervalleDiagramme[j] = valeur;
j++;
z++;
lecteurFichier.close(); // toujours fermer le fichier
Hi,
Thanks for your reply,
1) Yeah I have a method that asks the question and assigns it to a variable.
2) Well the z will stop once there is no lines to read no?
for the set.add(), I am not that familar...
I changed bit a code and I have this now:
if (z > 4) {
for (int i = 0; i < intervalleDiagramme.length; i++)
System.out.println(intervalleDiagramme);
if(intervalleDiagramme[i].equals(valeur))
System.out.println(intervalleDiagramme[i] + " " + valeur);
unique = false;
if (unique)
intervalleDiagramme[j] = valeur;
EDIT:
I figured a way to assign " " to all the values in my array. But I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 380
at TP3.lireFichier(TP3.java:305)
And my line 305 is: intervalleDiagramme[j] = valeur;
EDIT2:
So ok I found my mistake and corrected it. But I want to know is there a way of doing this without setting the size of the array? because sometimes there needs to be 21 values sometimes 19 and sometimes 20....
If I take out: = new String [21] out I get a NullPointer error...
Edited by: Ara1992Habs on Dec 13, 2009 7:29 AM
Edited by: Ara1992Habs on Dec 13, 2009 7:37 AM
Similar Messages
-
How to read .html file and store values into oracle table from html file
Hi all ,
How to read .html file and store values into oracle table from html file using pl/sql
Please Help.....Hi,
Kindly find following sample html code ,i want to store every value in different column in database .
<html><body><p/>
<div style="position:absolute;top:47px;left:37px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:47px;left:680px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:94px;left:151px;font-family:'Times New Roman';font-size:1pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:1080px;left:115px;font-family:'Times New Roman';font-size:8pt;white-space:nowrap;">4497743
</div>
<div style="position:absolute;top:1079px;left:442px;font-family:'Times New Roman';font-size:9pt;white-space:nowrap;"> Miclyn Express Offshore Pre-Quotation Disclosure
</div>
<div style="position:absolute;top:1079px;left:680px;font-family:'Times New Roman';font-size:9pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:1079px;left:723px;font-family:'Times New Roman';font-size:9pt;white-space:nowrap;">page 5
</div>
<div style="position:absolute;top:1083px;left:151px;font-family:'Times New Roman';font-size:1pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:107px;left:151px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>Attachment 2 ¿ indicative statement of 20 largest shareholders </b>
</div>
<div style="position:absolute;top:139px;left:262px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>Name </b>
</div>
<div style="position:absolute;top:131px;left:415px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>Number of Shares </b>
</div>
<div style="position:absolute;top:147px;left:458px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>Held </b>
</div>
<div style="position:absolute;top:131px;left:560px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>Percentage of </b>
</div>
<div style="position:absolute;top:147px;left:567px;font-family:'Times New Roman';font-size:10pt;white-space:nowrap;"><b>shares held </b>
</div>
<div style="position:absolute;top:179px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Macquarie Capital Group Limited 92,378,000
</div>
<div style="position:absolute;top:179px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:179px;left:618px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">34.00%r
</div>
<div style="position:absolute;top:179px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:212px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">HSBC Custody Nominees (Australia)
</div>
<div style="position:absolute;top:227px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Limited
</div>
<div style="position:absolute;top:220px;left:464px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">36,458,220
</div>
<div style="position:absolute;top:220px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:220px;left:618px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">13.42%
</div>
<div style="position:absolute;top:220px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:260px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Ray Rider Limited 27,170,000
</div>
<div style="position:absolute;top:260px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:260px;left:618px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">10.00%
</div>
<div style="position:absolute;top:260px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:300px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:300px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">7.96%
</div>
<div style="position:absolute;top:300px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:333px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">National Australia Bank Custodian
</div>
<div style="position:absolute;top:348px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Services
</div>
<div style="position:absolute;top:341px;left:464px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">12,866,550
</div>
<div style="position:absolute;top:341px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:341px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">4.74%
</div>
<div style="position:absolute;top:341px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:381px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Citigroup Nominees Pty Ltd 6,942,541
</div>
<div style="position:absolute;top:381px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:381px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">2.56%r
</div>
<div style="position:absolute;top:381px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:421px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:421px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">2.14%r
</div>
<div style="position:absolute;top:421px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:462px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">UBS Securities Australia Ltd 4,806,760
</div>
<div style="position:absolute;top:462px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:462px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">1.77%
</div>
<div style="position:absolute;top:462px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:494px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Merrill Lynch Equities (Australia)
</div>
<div style="position:absolute;top:510px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Limited
</div>
<div style="position:absolute;top:502px;left:472px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">4,325,000
</div>
<div style="position:absolute;top:502px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:502px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">1.59%
</div>
<div style="position:absolute;top:502px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:550px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Equities Ltd
</div>
<div style="position:absolute;top:542px;left:472px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">4,150,000
</div>
<div style="position:absolute;top:542px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:542px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">1.53%
</div>
<div style="position:absolute;top:542px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:575px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Bond Street Custodians Limited - A/C
</div>
<div style="position:absolute;top:590px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Institutional
</div>
<div style="position:absolute;top:583px;left:472px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">2,750,000
</div>
<div style="position:absolute;top:583px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:583px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">1.01%
</div>
<div style="position:absolute;top:583px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:623px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Cogent Investment Operations Pty Ltd 2,599,321
</div>
<div style="position:absolute;top:623px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:623px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.96%
</div>
<div style="position:absolute;top:623px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:663px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Skeet Nominees Pty Ltd 2,276,736
</div>
<div style="position:absolute;top:663px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:663px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.84%
</div>
<div style="position:absolute;top:663px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:704px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Diederik de Boer 1,917,561
</div>
<div style="position:absolute;top:704px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:704px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.71%
</div>
<div style="position:absolute;top:704px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:744px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Ecapital Nominees Pty Limited 1,594,736
</div>
<div style="position:absolute;top:744px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:744px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.59%
</div>
<div style="position:absolute;top:744px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:777px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Neweconomy Com Au Nominees Pty 9
</div>
<div style="position:absolute;top:792px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Limited <900 Account>
</div>
<div style="position:absolute;top:784px;left:472px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">1,594,7360
</div>
<div style="position:absolute;top:784px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:784px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.59%
</div>
<div style="position:absolute;top:784px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:825px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Sonray Capital Markets Pty Ltd 1,236,842
</div>
<div style="position:absolute;top:825px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:825px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.46%
</div>
<div style="position:absolute;top:825px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:865px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Argo Investments Limited 1,050,000
</div>
<div style="position:absolute;top:865px;left:531px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:865px;left:625px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">0.39%
</div>
<div style="position:absolute;top:865px;left:663px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">
</div>
<div style="position:absolute;top:905px;left:161px;font-family:'Times New Roman';font-size:11pt;white-space:nowrap;">Idameno (No 79) Nominees Pty Limited 724,210</div>
<div style="position:absolute;top:1103px;">
</body></html>
Thanks.......................... -
Read a text file and populate table
My email addres is [email protected]
I am new to java. My project requires me to read a text file and pick some values from the text file and populate a table in MS Access. The main fields are from the TEXT. Some of the columns to be read are:
Transaction ref.
Amount
User ref.
Date
The text file is as follows:
Receiver =
FBNINGLAXXX LT : A
FST BANK OF NIGERIA PLC
LAGOS
LAGOS
NG
NIGERIA
Transaction ref. = SPLOUK01P0008888 Related ref. = 00077003
Amount = 16675750, NGN Value/Date =
Format & Validation
Version = 0205 Checked = Minimum
Netw. Appl. = FIN Passed = Minimum
Sender to Receiver Instructions
Banking Prior. = User ref. = SPLOUK01P0008888
Warning Status =
Possible Duplicate Emission
Appl/Serv = SWIFT Interface
RP & Ft = SIfrom_SWIFT
Date/Time = 01/04/03 18:53:19
Text =
:20:SPLOUK01P0008888
:28D:1/1
:30:030401
:21:00077003
:32B:NGN16675750,00
:50H:/4072010014877
SPDC FBN East Main A/C
:57D:WEMA BANK PLC
PLOT 22 TRANS-AMADI BRANCH P.H.
PORT HARCOURT.
RIVERS STATE.
:59:/0421002101818
PROJECT MASTERS NIGERIA LTD.
C101 ELIOGBOLO VILLAGE OFF
EAST-WEST ROAD RUMUOKORO PORT HAR
COURT
:70:PM PCE-TS 03 001030226
:71A:OUR
Block 5:
{MAC:9F664844}{CHK:60EF6513E579}
Message History =
*Original (Completed)See in this case as you are dealing with Files and database. you need read the File by using the I/O Streams. if you have to select some particular values you can go Random access file.Once you have retrived values. You can go for the second part that is make a jdbc connection to database, and use simple SQL statements to populate those values into the table.
How this will give you a better picture -
Urgent Help:read from text file and write to table
Hi,
I'm a super beginner looking for a vi to read this data from a text file and insert it into a table:
#19
Date: 05-01-2015
ID= 12345678
Sample_Rate= 01:00:00
Total_Records= 2
Unit: F
1 03-23-2015 10:45:46 70.1 3.6
2 03-23-2015 11:45:46 67.7 2.7
Output table
# date time x y Sample rate Total Records
1 03-23-2015 10:45:46 76.8 2.8 01:00:00 2
2 03-23-2015 10:45:46 48.7 2.1 01:00:00 2
Thanks for your help in advance.
Attachments:
sample.txt 1 KBjcarmody wrote:
Will there always be the same number of rows of noise header information?
Show us how you've read the data and what you've tried to do to parse it. Once you've got the last rows, you can loop over them using Spreadsheet String to Array (after cleaning up a few messy spaces).
Jim,
I didn't know you're that active on here.
Yes, There will always be the same number of noise header information.
I'll show you in person
Regards, -
How can i read the text files and buffer the data in Vector?
hi. I have been running into this problem for days, but with no luck and losing right direction.
The problem is : I am trying to read a text file and buffer the data into a
Queue for each user.
the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
17 8 2 18 512
18 9 2 19 512
19 10 2 20 512
20 1 3 21 512
21 2 3 22 512
22 3 3 23 512
23 4 3 24 512
24 5 3 25 512
25 6 3 26 512
26 7 3 27 512
27 8 3 28 512
28 9 3 29 512
29 10 3 30 512
30 1 4 31 512
31 2 4 32 512
32 3 4 33 512
33 4 4 34 512
34 5 4 35 512
35 6 4 36 512
36 7 4 37 512
37 8 4 38 512
38 9 4 39 512
39 10 4 40 512
40 1 5 41 512
41 2 5 42 512
42 3 5 43 512
43 4 5 44 512
44 5 5 45 512
45 6 5 46 512
46 7 5 47 512
47 8 5 48 512
48 9 5 49 512
49 10 5 50 512
50 1 6 51 512
51 2 6 52 512
52 3 6 53 512
53 4 6 54 512
54 5 6 55 512
55 6 6 56 512
56 7 6 57 512
57 8 6 58 512
58 9 6 59 512
59 10 6 60 512
60 1 7 61 512
61 2 7 62 512
62 3 7 63 512
63 4 7 64 512
64 5 7 65 512
65 6 7 66 512
66 7 7 67 512
67 8 7 68 512
68 9 7 69 512
69 10 7 70 512
70 1 8 71 512
71 2 8 72 512
What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
I already created a class called Class packet:
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
/** Creates a new instance of packet */
public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
this.timestamp = timestamp;
this.user_id=user_id;
this.packet_id=packet_id;
this.packet_seqno=packet_seqno;
this.packet_size=packet_size;
}then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
any idea and sample code will be appreciated.Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave. -
1.is it possible to read a .xls file and load it into an oracle table
1.is it possible to read a .xls file and load it into an oracle table, using oracle database or oracle forms i.e. either utl_file, or text_io, or any other oracle tool.
As far as I know we need a csv file or a txt ( tab delimited) file ?
2.Are there any windows tools for the sameHi,
If you want to use the DDE package to read the XLS file then yes, you will neeed to know the number of rows and columns in the input file.
i.e. How will you know :
1) How many columns are there in the input file.
If I have a XLS file with the following data :
R1C1 R1C2 R1C3 R1C4 R1C5 R1C6 R1C7
xxx xx x
Where R represents row and C represents column, then how will you know the each row has 7 columns. If you know the answer upfront, then it's not a issue.
Using the DDE apprach, you will have to specify the RowNum and the ColumnNo of each idividual cells to read/write data from xls sheet.
Look at the syntax in my ealier post.
using the other approch (i.e. comma delimited text file - CSV file) , you need not know the number of columns as you can loop thru the input record till the last column is read.
All you have to do is to look for the 'n' occurances of the field delimiter say ',', do a substr from the current position to the point where the ',' was found.
This process is to be repeated in a loop till all columns are read.
The TEXT_IO package can trap for EOF (End Of File).
Hope I made myself clear.
-- Shailender Mehta -- -
Reading a text file and putting it in a textarea
hi can u tell me how to read a text file and display the contents in a text area using jsp please?
thanks :o)<%@ page import="java.sql.*, java.io.*" %>
<HTML>
<HEAD>
<TITLE>User Application Area</TITLE>
<SCRIPT LANGUAGE="javascript" SRC="cal2.js">
</SCRIPT>
<SCRIPT LANGUAGE="javascript" SRC="cal_conf2.js"></SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:fypproject","","");
Statement st = con.createStatement();
String email = (String)session.getAttribute("email");
String levelStatus = (String)session.getAttribute("levelStatus");
String details = "SELECT PD.Forename, PD.Surname, L.Level_Name FROM Personal_Details PD,
Login_Details LD, Levels L WHERE PD.Email_Address = '" + email + "' AND PD.Email_Address =
LD.Email_Address AND LD.Level_ID = '" + levelStatus + "' AND LD.Level_ID = L.Level_ID";
ResultSet rsDet = st.executeQuery(details);
if(rsDet.next()) {
String forename = rsDet.getString("Forename");
String surname = rsDet.getString("Surname");
String levelName = rsDet.getString("Level_Name");
%>
<DIV ALIGN="center"><H1>User Application Arena</H1></DIV>
<BR>
<H4>Welcome back <% out.println(forename + " " + surname); %> </H4>
<BR>
Your status is:
<FONT COLOR = "red">
<% out.println(levelName); %>
</FONT>
<BR>
<%
if(levelStatus.compareTo("0")==0) {
%>
<BR>
<DIV ALIGN="center">
Please come back later and re-check your status to see if your application has progressed. If it has
been more than a week since you submitted it please phone the HR department on 020 7123 4567
<BR><BR>
Log Out
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("1")==0) {
%>
<FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
<DIV ALIGN="center">
Congratulations, we would like to invite you for a First Round tests and interview. Please select a
date that would suit you on our online calendar below
<BR><BR>
<SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
<BR><BR>
<INPUT TYPE="text" NAME="firstinput" SIZE=20>
<BR><BR>
<INPUT TYPE="submit" VALUE="Confirm">
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("2")==0) {
%>
<FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
<DIV ALIGN="center">
Congratulations, we would like to invite you for a Second Round interview. Please select a date that
would suit you on our online calendar below
<BR><BR>
<SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
<BR><BR>
<INPUT TYPE="text" NAME="firstinput" SIZE=20>
<BR><BR>
<INPUT TYPE="submit" VALUE="Confirm">
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("3")==0) {
File inFile = new File("offer.txt");
StringBuffer sb = new StringBuffer();
BufferedReader buf = new BufferedReader(new FileReader(inFile));
while (buf.ready()) {
sb.append(buf.readLine());
buf.close();
%>
<TEXTAREA NAME ="text" ROWS="10" COLS="60">
<%= sb.toString() %>
</TEXTAREA>
<%
else if(levelStatus.compareTo("4")==0) {
out.println("send rej email");
st.close();
con.close();
%>
</BODY>
</HTML>
THANKS!! :o) -
How can FMS create a text file and write data into it in the Server application folders?
Recently, I writed a programe about creating a text file and writing data into it in the server application folder. My code is as following:
var fileObj = new File("/MyApp/test.txt");
if( fileObj != null)
if(fileObj.open( "text", "append"))
fileObj.write( " ———— Chat Info Backup ————\r\n" );
fileObj.close( );
trace("Chat info backup document :" + fileObj.name + " has been created successfully!");
But when I run it, FMS throw the error as following: File operation open failed ; TypeError: fileObj has no properties.
Can you help me ? Thanks in advance.
Supplement: The text file named test.txt doesn't exist before create the fileObj, an instance of File Class.Is MyApp the name of the application directory, or is it a child of the application directory? If myApp is the app name, just use test.txt as the path flag in the file constructor.
-
Issue : Read a text file and print the same
Hi, My requirement is to read a text file and print it the same way.
import java.io.BufferedReader;
import java.io.FileReader;
public class CatFile {
public static void main(String[] args) throws Exception
FileReader file = new FileReader("D:/Test/Allfiles.txt");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine();
while (line != null)
text += line;
line = reader.readLine();
System.out.println(text);
The text file i used contains
A
B
C
but my output is ABC.
What change should be made to print it the same way in the txt file ?Hi EJP,
I modified the code based on your suggestion and now its working as expected. Thanks
Modified code :
import java.io.BufferedReader;
import java.io.FileReader;
public class CatFile {
public static void main(String[] args) throws Exception
FileReader file = new FileReader("D:/Test/Allfiles.txt");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine();
while (line != null)
System.out.println(line);
line = reader.readLine();
text += line;
} -
Read multiple text files and sort them
I am trying to read multiple text files and store the data from the file in vector.
but for days. I am with no luck. anyone can help me out with it? any idea of how to sort them will be appreciated.
Below is part of the code I implemented.
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
public packet(int timestamp0,int user_id0, int packet_id0,int packet_seqno0, int packet_size0)
timestamp = timestamp0;
user_id=user_id0;
packet_id=packet_id0;
packet_seqno=packet_seqno0;
packet_size=packet_size0;
public void setTime(int atimestamp)
this.timestamp=atimestamp;
public void setUserid(int auserid)
this.user_id=auserid;
public void setPacketid(int apacketid)
this.packet_id=apacketid;
public void setPacketseqno(int apacketseqno)
this.packet_seqno=apacketseqno;
public void setPacketsize(int apacketsize)
this.packet_size=apacketsize;
public String toString()
return timestamp+"\t"+user_id+"\t"+packet_id+"\t"+packet_seqno+"\t"+packet_size+"\t";
}Here is the data from part of the text files. ( the first column is timestamp, second is userid, third is packetid.....)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512Here's a standard idiom for object-list-sorting:
/* cnleafdata.txt *********************************************
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
import java.util.*;
import java.io.*;
public class Packet implements Comparable<Packet>{
private int timeStamp;
private int userId;
private int packetId;
private int packetSeqno;
private int packetSize;
public Packet(int timeStamp0, int userId0, int packetId0,
int packetSeqno0, int packetSize0) {
timeStamp = timeStamp0;
userId = userId0;
packetId = packetId0;
packetSeqno = packetSeqno0;
packetSize = packetSize0;
public Packet(String timeStamp0, String userId0, String packetId0,
String packetSeqno0, String packetSize0) {
this(Integer.parseInt(timeStamp0), Integer.parseInt(userId0),
Integer.parseInt(packetId0), Integer.parseInt(packetSeqno0),
Integer.parseInt(packetSize0));
public Packet(String[] a){
this(a[0], a[1], a[2], a[3], a[4]);
public void setTime(int aTimeStamp){
timeStamp = aTimeStamp;
public void setUserId(int aUserId){
userId = aUserId;
public void setPacketId(int aPacketId){
packetId = aPacketId;
public void setPacketSeqno(int aPacketSeqno){
packetSeqno = aPacketSeqno;
public void setPacketSize(int aPacketSize){
packetSize = aPacketSize;
public int getUserId(){
return userId;
public String toString(){
return String.format
("%2d %2d %2d %2d %4d", timeStamp, userId, packetId, packetSeqno, packetSize);
public int compareTo(Packet otherPacket){
return userId - otherPacket.getUserId();
/* main for test */
public static void main(String[] args){
String line;
ArrayList<Packet> alp;
alp = new ArrayList<Packet>();
try{
BufferedReader br = new BufferedReader(new FileReader("cnleafdata.txt"));
while ((line = br.readLine()) != null){
// if (! recordValid(line)){
// continue;
String[] ar = line.split("\\s");
alp.add(new Packet(ar));
catch (Exception e){
e.printStackTrace();
System.out.println("[original]");
for (Packet p : alp){
System.out.println(p);
System.out.println();
Collections.sort(alp);
System.out.println("[sorted by user ID]");
for (Packet p : alp){
System.out.println(p);
} -
Where does this java program read a text file and how does it output the re
someone sent this to me. its a generic translator where it reads a hashmap text file which has the replacement vocabulary etc... and then reads another text file that has what you want translated and then outputs translation. what i don't understand is where i need to plugin the name of the text files and what is the very first line of code?
[code
package forums;
//references:
//http://forums.techguy.org/development/570048-need-write-java-program-convert.html
//http://www.wellho.net/resources/ex.php4?item=j714/Hmap.java
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
public class Translate {
public static void main(String [] args) throws IOException {
if (args.length != 2) {
System.err.println("usage: Translate wordmapfile textfile");
System.exit(1);
try {
HashMap words = ReadHashMapFromFile(args[0]);
System.out.println(ProcessFile(words, args[1]));
} catch (Exception e) {
e.printStackTrace();
// static helper methods
* Reads a file into a HashMap. The file should contain lines of the format
* "key\tvalue\n"
* @returns a hashmap of the given file
@SuppressWarnings("unchecked")
private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException {
BufferedReader in = null;
HashMap map = null;
try {
in = new BufferedReader(new FileReader(filename));
String line;
map = new HashMap();
while ((line = in.readLine()) != null) {
String[] fields = line.split("\\t", 2);
if (fields.length != 2) continue; //just ignore "invalid" lines
map.put(fields[0], fields[1]);
} finally {
if(in!=null) in.close(); //may throw IOException
return(map); //returning a reference to local variable is safe in java (unlike C/C++)
* Process the given file
* @returns String contains the whole file.
private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException {
BufferedReader in = null;
StringBuffer out = null;
try {
in = new BufferedReader(new FileReader(filename));
out = new StringBuffer();
String line = null;
while( (line=in.readLine()) != null ) {
out.append(SearchAndReplaceWordsInText(words, line)+"\n");
} finally {
if(in!=null) in.close(); //may throw IOException
return out.toString();
* Replaces all occurrences in text of each key in words with it's value.
* @returns String
private static String SearchAndReplaceWordsInText(Map words, String text) {
Iterator it = words.keySet().iterator();
while( it.hasNext() ) {
String key = (String)it.next();
text = text.replaceAll("\\b"+key+"\\b", (String)words.get(key));
return text;
* @returns: s with the first letter capitalized
String capitalize(String s)
return s.substring(0,0).toUpperCase() + s.substring(1);
}without what arguments?Without any arguments. If there are no arguments, there are no arguments of any kind. If you have a zoo with no animals in it, it's not meaningful to ask whether the animals which are not there are zebras or elephants.
does it prompt me to give it a text file name?Apparently.
when i run it this is all i get:
usage: Translate wordmapfile textfile
Press any key to continue...Right. And "wordmapfile" is almost certainly supposed to be a file that holds the word map, and "textfile" is almost certainly the file of text that it's going to translate. -
Take an existing text file and modify values
I’m looking to take an existing text file and modify certain values inside of it. Then save it to a new file, with all the same formatting as the original. The file format is not uniform and can change.
Basically the file is:
Random numbers and letters of unknown length for an unknown number of lines.
Label="Test_#"
Description
String
X=123
Y=456
Z=-789
20 lines of strings with numbers in them
Label="Test_#2"
Description
String
X=-1232
Y=4562
Z=7892
Then it repeats a set number of times.
I want to modify the X Y and Z = values for each Test_#.
I’ve managed to import the important values into a numeric array and I have a different array with values that will replace the existing ones. I’m having troubles replacing the existing ones. There are no zeros before or after the existing numbers so they are all different lengths.
If anyone has any sample code that does anything similar please post it. I’m sure someone has done something like this in the past.
Solved!
Go to Solution.I just thought I would throw this out there. Can you make the .txt file tokenized? This would make searching for specific parameters much easier.
Reese, (former CLAD, future CLD)
Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home -
Reading a text file and connecting two server
Hi,
I am newbie at java and I have two question ,
asume you have two server and a client. every server reads its own text file and the client connect both of them and read output data, and counts number of words. you must use socket programming to communicate to servers.
I need litle code.
Thanks for your helpHi,
While using ArrayList, use add your elements into it
as an object subtype if you do not specify ArryList
certain type.
But recall that if you use certain
type(ArrayList<String>,....), you do not add any
other different type element.What the heck is this all about Merde? -
Read from text file and seperate column
hello,
I have a problem reading my text file. This text file is downloaded from weather link. All data will be changed upon the selection of user. my problem is I can read the data column by column but i cannot retrive the right column header for each data. I also attached the test file. Can somebody help me? Thanks in advance..
Attachments:
download.txt 8 KB
read text file.JPG 11 KB
read data.JPG 43 KBHi
Sorry, I missed that one. The file formatting is strange though. It uses spaces to separate columns but also within columns. I attached a modified VI that tries to take care of that, but it fails at the columns "Solar Energy" and "Hi Solar Rad.". This is very difficult to read programmatically as there's one space each between "Solar", "Hi", and "Solar" again. So how do we distinguish between column separator and space within column?
Is download.txt the original file? Or was it probably modified by an editor that would replace tabs by space characters?
Attachments:
test-mod-2.vi 11 KB -
Reading multiple text files and writing them to one text file
Hi,
I'm trying to read a number of text files and write them to a single master file. My program reads all the files but only writes the last one to the master file.
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
// Input/Output Classes
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.GridLayout;
public class Actor implements ActionListener
public static String DataRoot = "I:\\JAVA\\UBP\\DAT
public static JFrame SW = new JFrame();
public static JTextField txtSPath;
public static JTextArea txtTable;
public void actionPerformed( ActionEvent e )
String Command = e.getActionCommand();
if (Command.equals("Process") )
SetupWin();
ProcessAll();
public void SetupWin()
SW.setTitle("void");
SW.setSize(300,400);
SW.setLayout(new GridLayout(6,1));
txtSPath = new JTextField(40); SW.add(txtSPath);
txtTable = new JTextArea(10, 40); SW.add(txtTable);
SW.setVisible(true);
public void ProcessAll()
Process("Dunstable","Finance");
Process("Dunstable","Production");
Process("Dunstable","Sales");
public void Process(String Town, String Dept)
String SPath = DataRoot + Town + "
" + Dept + ".txt";
String MPath = DataRoot + "masterFile" + ".txt";
txtSPath.setText(SPath);
String message = "Trying " + SPath;
System.out.println(message);
String SlaveTable=message;
try// if following fails an exception is thrown
Scanner Slave = new Scanner(new FileInputStream(SPath)); // reads slave file
PrintWriter outputStream = null;
outputStream = new PrintWriter(new FileOutputStream(MPath));
while ( Slave.hasNextLine() ) // reads text line by line
//Read and output next record
String PartRecord = Slave.nextLine();
String FullRecord = Town + " " + PartRecord;
System.out.println(FullRecord);
outputStream.println(FullRecord);
Slave.close();
outputStream.close();
txtTable.setText(SlaveTable);
//An Exception Error would be THROWN by above & CAUGHT below
catch(FileNotFoundException e)
message = "Could Not Find " + SPath;
System.out.println(message); //console
txtSPath.setText(message); //window
catch(IOException e)
System.out.println("Slave I/O Problem " + SPath);
}Edited by: Ardour on Mar 4, 2008 1:53 PMI haven't looked closely, but my spidey sense tingles at this:
new FileOutputStream(MPath)This will clobber (erase) the previous contents of the file. Open in append mode:
new FileOutputStream(MPath, true)Of course, if the file exists before you run this code, you will end up append to the original contents. If that is not wanted, consider using File's delete method first.
Maybe you are looking for
-
On 9/29 I ordered an iPhone 6 Plus 128GB as an edge up from my 5S, swiped my card at the store to pay the Edge Up fee, and was told 10/31 was the expected ship date. Didn't see the order on my My Verizon account, spoke with 3 representatives on the p
-
I had an iphone 4 and when I downloaded the IOS7 started having problems. Gone the phone keypad, could not type more names of my contacts in the phone search. I decided to buy the iphone 5S and since downloaded the IOS7.1.2 the search of your phone c
-
Payment terms and Due date field gets emptied after residual clearing
Hi There is advance of Rs.50000 in Vendor ledger and Invoice of Rs.200000 (with payment term - G019) I cleared these two line items (residual clearing). One new line item got created of Rs.150000. When i saw that line item, i saw that there payment t
-
TS3297 iTunes library.iTl cannotbe read because ity was created by new version
upgraded from OSX 10.5.7 to OSX 10.6.8; when opening iTunes it ask for OK in terms; oked; when I went to open itunes it gave a message"iTunes can not be read because it was created by a newer version of iTunes"
-
Hi guys, we are using three node cluster with Windows Server 2012R2. Our virtual machines are virtual desktops with Windows 8.1 guest OS, 4 vCPU and 8 GB of dynamic memory. Sometimes dynamic memory stops working, guest OS is not able to allocate more