Load text file into applet

hi,
I am new to java and really need some help.
I want to load / read a text file in my applet line by line
the text file looks like:
P,161,127,3,ff6599c2
P,161,127,3,ff6599c2
P,161,128,3,ff6599c2
P,161,129,3,ff6599c2
etc.
the code I tied and did not work looks like:
class read
     public void main( String[] args)
          int i;
          if (args.length < 1)
               System.out.println("Please enter file: read<datei>");
               System.exit(-1);
          try
               BufferedReader in =new BufferedReader(new FileReader( args[0]));
               String line = new String();
               while((line=in.readLine())!=null)
                    System.out.println( line );
          catch(IOException e2)
has anybody an idea how to do it?
Thanks a lot
Silke

<PRE>
First off you need to create a class which extends the
Applet class. The applet class does not have the
method "public static void main(String args[])". Instead it has a method "init()". In the "init" method you should
write the code that you would write in "main". The "init"
method is only executed once. When the applet is first downloaded. Here is a sample code, but there is one other factor to note. Applets have trouble accessing
files on computers. This goes above and beyond the
applet sandbox which locks up an applet. In my experiences I have only managed to read and write text
files to the desktop through applets. The program can
be used by entering the file name in the text field
at the top of the applet and then clicking the "Read File"
button at the bottom of the applet. This code segment is untested and it has been some time since I have done
applet programming but it should work. You may have to
edit the security policy file(security.policy) to grant permission to your codebase before this functions properly because it involves reading from the file system. The grant should look something like this(if you are running under unix/linux I believe you would substitute"file:\\\" with "file:/"):
grant codeBase "file:\\\<Directory Path that contains
the MyApplet class" {
java.io.FilePermission "read", "*"
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
<Applet Code="MyApplet" width="300", height="300">
</Applet>
class MyApplet extends Applet
implements ActionListener {
TextArea ta=new TextArea();
Button readFB=new Button("Read File");
TextField tf=new TextField();
public void init() {
setLayout(new BorderLayout());
Panel tempPan=new Panel();
tempPan.setLayout(new BorderLayout());
tempPan.add("West", new Label("File Name:"));
tempPan.add("Center", tf);
add("North", tempPan);
add("Center", ta);
add("South", readFB);
readFB.addActionListener(this);
setSize(300, 300);
show();
public void actionPerformed(ActionEvent ae) {
String action=ae.getActionCommand();
if(action.equals("Read File")) {
String strFileName=tf.getText();
BufferedReader br=new BufferedReader(new FileReader(new File(strFileName)));
ta.setText("");
String nextLine="";
while((nextLine=br.readLine())!=null) {
ta.append(nextLine+"\n");
br.close();
ps: be careful when modifying security policy file.
It will affect all applet code that is loaded from the
codeBase specified. If no codeBase is specified it
will apply to all codeBases leaving you vulnerable
to malicious applets. Good luck.
</PRE>

Similar Messages

  • SQL Loader - Loading Text File into Oracle Table that has carriage returns

    Hi All,
    I have a text file that I need to load into a table in Oracle using SQL Loader. I'm used to loading csv or comma delimited files into Oracle so I'm not sure what the syntax is when it comes to loading a text file that essentially has one value per row and each row is separated by a carriage return. So when you open the text file, the records look like this:
    999999999 <CRLF>
    888888889 <CRLF>
    456777777 <CRLF>
    456555535 <CRLF>
    345688888 <CRLF>
    So each row is separated by a hard return and I need to tell sql loader that the hard return or next row is the next value to insert into the table. Below is an example of a control file I tend to use as a template for loading csv files but I need to modify it to accomodate this new structure.
    OPTIONS (DIRECT=TRUE,ROWS=100000)
    UNRECOVERABLE
    LOAD DATA
    INFILE 'C:\input.txt'
    BADFILE 'C:\input.bad'
    APPEND
    INTO TABLE TEST_TABLE
    FIELDS TERMINATED BY ","
    TRAILING NULLCOLS
    COLUMN_1
    How to I modify the control file above to use hard returns as the field/row delimiter for my text file?
    Thanks

    Hi there,
    Obviously my intention wasn't to post the same message 4 times....I pressed the "Submit Message" button but the submission hung and I pressed it a few times and finally it worked but it created several versions of my post. You need to allow users the ability to delete there own postings...I was looking for this option but didn't have it.
    Sorry

  • How to get applet to load text file and use it

    The applet is loaded from my site and the short text file is updated by a perl script in my cgi-bin, which is called whenever someone loads the html that loads my applet.
    The text file is just a counter string and I'd like to use it to display #.gif's at a certain place on the applet window (no problem there if I can get the text file into the applet).
    How would I get the applet to load the text file into a string or array?
    It has a running thread and I'd like it to update it periodically.

    I believe you can do that with Class.getResourceAsStream.
    Or you can do it explicitly with java.net.* stuff.

  • 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

  • Open and read from text file into a text box for Windows Store

    I wish to open and read from a text file into a text box in C# for the Windows Store using VS Express 2012 for Windows 8.
    Can anyone point me to sample code and tutorials specifically for Windows Store using C#.
    Is it possible to add a Text file in Windows Store. This option only seems to be available in Visual C#.
    Thanks
    Wendel

    This is a simple sample for Read/Load Text file from IsolateStorage and Read file from InstalledLocation (this folder only can be read)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Storage;
    using System.IO;
    namespace TextFileDemo
    public class TextFileHelper
    async public static Task<bool> SaveTextFileToIsolateStorageAsync(string filename, string data)
    byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(data);
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    var file = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
    try
    using (var s = await file.OpenStreamForWriteAsync())
    s.Write(fileBytes, 0, fileBytes.Length);
    return true;
    catch
    return false;
    async public static Task<string> LoadTextFileFormIsolateStorageAsync(string filename)
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    async public static Task<string> LoadTextFileFormInstalledLocationAsync(string filename)
    StorageFolder local = Windows.ApplicationModel.Package.Current.InstalledLocation;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    show how to use it as below
    async private void Button_Click(object sender, RoutedEventArgs e)
    string txt =await TextFileHelper.LoadTextFileFormInstalledLocationAsync("TextFile1.txt");
    Debug.WriteLine(txt);
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • 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. 
    Thanks

    Hi 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

  • Using importTextData to load text files

    I have been having a real issue  trying to load data from text files (tab delimited text file) into my  form.
    It  works fine if I use importTextData() with no parameters and it prompts  for the file name, then the row, but if I try and pass the path and row  it comes back with a -2 result "User Cancelled Row Select".
    My path is  formatted as so: "/C/temp/importfile.txt"
    It has to do with the path  somehow... otherwise my file would not load properly when browsed.
    And before  people let me know I can import my information via an XML file, yes I  know, but for this task, is not an option.
    The end goal is to have a fixed  drop-down on the form and depending on which item they select, Acrobat  will load a text file into various controls.
    I have attached my sample if  someone wants to take a look.
    Any help people can give is greatly appreciated.
    Paul

    My example was not very good. I replaced it with a new (see attached).
    Previously I found my problem to be the header row in the text file was not formatted properly. ie. rather than have "task" as the column header it had to be frmProgressCard[0].frmTasks[0].tblTasks[0].rowTask[0].task[0]
    That does not work any longer.
    I save all the work in LiveCycle as Adobe Dynamic XML Form and then open it in Acrobat Pro to test, but still will not load my data. Returns with "invalid row" error.
    So I think the problem is that first row that is suppose to link up with the text fields in the form, but I can't seem to find the proper format.
    The help file only says to put in the field names, ie. "task", but that does not work.
    Thanks
    Paul

  • How to read\write text file into oracle database.

    Hello,
    I am having text file called getInfo in c:\temp folder. I would like to populate data from text file to data base. How to proceed. Could anybody help me out.
    Thanks,
    Shailu

    Here is a web page with easy to follow instructions regarding external files: http://www.adp-gmbh.ch/ora/misc/ext_table.html.
    Now I understand what all the excitement is over external tables.
    "External tables can read flat files (that follow some rules) as though they were ordinary (although read-only) Oracle tables. Therefore, it is convenient to use external tables to load flat files into the DB." -from the above link.

  • Loading XML files into an 8.0.6 database...

    Hi,
    I've got an Oracle 8.0.6 instance (Sun E250 Solaris 5.7) with multiple import data feeds. I am currently using SQL*Loader to load this data which are flat text delimited files. My data feeds will soon be supplying XML files instead of these flat files which is great, unfortunately, I will not be able to upgrade in 8.1.7 in time so that I can use the XML parser.
    Is there anyway I can use SQL*Loader or some other tool to load XML files into my 8.0.6 database? If there is a way, could someone please send the information I would need to help perform this task?
    Thanks for all your help...
    Gerry D'Costa
    Database Administrator
    [email protected]
    12Snap.com

    Check out the Oracle XDB Developer's Guide, Chapter 3. There is an example of using BFileName function to load the xml files from a directory object created using create or replace directory. It works really well.
    Ben

  • Can load text file in Windows - not on the Mac?

    I have some code that loads a text file into an array that works fine in windows, but fails on the Mac  I'm sure it's a path issue but I've spent several hours trying to work this out.
    Windows code works fine:
        var textPath =  "c:\\temp\\textfile.txt";
         try {
            var myFile = File(textPath);
            var mymenuItems=[];
            var menuItems=[];
            myFile.open('r');
            while(!myFile.eof){
                mymenuItems.push(myFile.readln());
            myFile.close();
    Mac Code Fails
      var textPath = '/User/wizbowes/Desktop/text.txt';
         try {
            var myFile = new File(textPath);  //tried both with and without new - same effect
            var mymenuItems=[];
            var menuItems=[];
           myFile.open('r');
       while(!myFile.eof){
                mymenuItems.push(myFile.readln());
    When debugging on the mac myFile.eof shows true straight after I open the file and therefore never enters the loop to populate the array
    What on earth am I doing wrong?

    1. For files on your desktop you can use a shortcut.
    var textPath = '~/Desktop/text.txt';
    2. Make sure the file object is valid before you open for reading. The new keyword is not really needed it just make clear in the code that you are creating a new file object. However just creating a file object does not means that the file already exists. You could have an invalid path.
    try {
            var myFile = new File(textPath);
            if(myFile.exists){
               // rest of the code
    3. If you don't want to check that the file exists you could check the return of the file.open() method. It should return true if it opened the file when opening an existing file.
    var openSuccess = myFile.open('r');
    if(openSuccess){
        // some code that reads from the file here

  • How to load text file data to Oracle Database table?

    By using Oracle Forms, how to load text file data to Oracle Database table?

    Metalink note 33247.1 explains how to use text_io as suggested by Robin to read the file into a Multi-Row block. However, that article was written for forms 4.5 and uses CREATE_RECORD in a loop. There was another article, 91513.1 describing the more elegant method of 'querying' the file into the block by transactional triggers. Unfortunately this more recent article has disappeared without trace and Oracle deny its existence. I know it existed as I have a printed copy in front of me, and very useful it is too.

  • Unable to Upload data from text file into BEx Analyzer selection screen

    Hi,
    No response from BEx Analyzer when I am trying to upload around 40,000 material from text file into BEx Analyzer selection screen using "Upload selections" options. But I am able to upload only 10,000 material from text file.  I never faced same kind of issue when I am using BEx Analyzer 3.x.  Please let me know I have to change any settings related to BEx or any other.
    Thanks
    Sri Krishna Ponnada.

    Hello
    It seems you are reaching the .NET memory limitation informed in note 1040454.
    Because 3.5 does not use .NET it can work that.
    Regards,
    Ricardo

  • Reading String (Name-Value) from text file into XML

    Hi,
    I have a requirement for reading a text file and converting each entry of that text file into XML format. I have not came across such thing yet so looking for some ideas. I am using SQL Server 2005 and here is a sample entry from my source text file,
    Jun 4 14:31:00 zzzz64x02 fff:
    INPUT(ty=XYZ,Prefix=15063,dn=78787878787878,sgk=100.139.201.48,xxn=87878,ani=656565656565,ogrp=F7ZX05,ogtxt=NNNNN,ogx=NNNNN,oci=0xe00ac,ogi={NOA=INT,BC=1,SIG-TYPE=ZIP});
    PROCESS(ty=0x100000,cu=32880,Name=XOXOXOX,pc=88017,pd=24,dd=880175,pk=880175,rd=115472,ca=BGD,reg=RW,cdp=1,ai=245359,grp=2648,sl=9);
    OUTPUT(ty=XXXX,ret=0,rl=
    {i=1,su=99999,rizID=61084,skid=06,truckgp=1084,dd=8801,dn=78787878787878}
    I will get multiple entries like this in my source text file which I have to convert into XML (using TSQL).
    Any help will be useful.
    Regards.
    'In Persuit of Happiness' and ..... learning SQL.

    And I'm telling you that this is a bad option. You would use the vaccum cleaner to wash the dishes, would you?
    If you for some reason would do this task in SQL Server, you would implement it as a CLR stored procedure, but from what you have said I don't understand why you would do this server-side at all.
    What's wrong with the current C# solution?
    Erland Sommarskog, SQL Server MVP, [email protected]
    Got it.  I was just looking for the available options, nothing wrong with my C# solution. And yes, I don't use vacuum cleaner to wash dishes.
    'In Persuit of Happiness' and ..... learning SQL.

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • How to import data from a text file into a table

    Hello,
    I need help with importing data from a .csv file with comma delimiter into a table.
    I've been struggling to figure out how to use the "Import from Files" wizard in Oracle 10g web-base Enterprise Manager.
    I have not been able to find a simple instruction on how to use the Wizard.
    I have looked at the Oracle Database Utilities - Overview of Oracle Data Pump and the Help on the "Import: Files" page.
    Neither one gave me enough instruction to be able to do the import successfully.
    Using the "Import from file" wizard, I created a Directory Object using the Create Directory Object button. I Copied the file from which i needed to import the data into the Operating System Directory i had defined in the Create Directory Object page. I chose "Entire files" for the Import type.
    Step 1 of 4 is the "Import:Re-Mapping" page, I have no idea what i need to do on this page. All i know i am not tying to import data that was in one schema into a different schema and I am not importing data that was in one tablespace into a different tablespace and i am not R-Mapping datafiles either. I am importing data from a csv file.
    For step 2 of 4, "Import:Options" page, I selected the same directory object i had created.
    For step 3 of 4, I entered a job name and a description and selected Start Immediately option.
    What i noticed going through the wizard, the wizard never asked into which table do i want to import the data.
    I submitted the job and I got ORA-31619 invalid dump file error.
    I was sure that the wizard was going to fail when it never asked me into which table do i want to import the data.
    I tried to use the "imp" utility in command-line window.
    After I entered (imp), i was prompted for the username and the password and then the buffer size as soon as i entered the min buffer size I got the following error and the import was terminated:
    C:\>imp
    Import: Release 10.1.0.2.0 - Production on Fri Jul 9 12:56:11 2004
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    Username: user1
    Password:
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
    tion
    With the Partitioning, OLAP and Data Mining options
    Import file: EXPDAT.DMP > c:\securParms\securParms.csv
    Enter insert buffer size (minimum is 8192) 30720> 8192
    IMP-00037: Character set marker unknown
    IMP-00000: Import terminated unsuccessfully
    Please show me the easiest way to import a text file into a table. How complex could it be to do a simple import into a table using a text file?
    We are testing our application against both an Oracle database and a MSSQLServer 2000 database.
    I was able to import the data into a table in MSSQLServer database and I can say that anybody with no experience could easily do an export/import in MSSQLServer 2000.
    I appreciate if someone could show me how to the import from a file into a table!
    Thanks,
    Mitra

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

Maybe you are looking for