Need help with "reading" files ...

Okay, here's the scoop in two versions ...
The Short and Sweet:
I'm VERY new to Java programming, but before I dedicate a lot of time into my project, I need to know first if it is possible for a java.class applet (running in a browser, online) to read from a text file located on the (remote) server - ie: the same server and path as the java.class applet is located.
The Long and Confusing:
The primary objective is to recursively read from a constantly changing data/text file (generated by a php script), then "parse" that data into certain variables which in turn affect the (browser) output viewed by the visitor. A simplified example of this would be to capture x-y coordinates generated by a perpetually running php script (via a "shared" text file), then the applet would use this "read" data to constantly update the x-y positions of two (or more) graphical objects within the running applet.
Hope this makes sense. I'm not asking anybody to actually code this for me (though an example would be nice) ... I really just need to know if it can be done before delving into this somewhat paramount project. Thanks.
--Mikey

The Short and Sweet:
I'm VERY new to Java programming, but before I
dedicate a lot of time into my project, I need to know
first if it is possible for a java.class applet
(running in a browser, online) to read from a text
file located on the (remote) server - ie: the same
server and path as the java.class applet is located.
It is possible to use an Applet to read a file from the server, but you need to use a URL stream, not a file stream because of the Applet security constraints. Applet.getCodeBase() will return the URL of the directory where the Applet is. You can use the URL to create a URL to the file. Then read the new URL's InputStream.

Similar Messages

  • Need help with connecting file inputs to arrays

    In this assignment I have a program that will do the following: display a list of names inputed by the user in reverse order, display any names that begin with M or m, and display any names with 5 or more letters. This is all done with arrays.
    That was the fun part. The next part requires me to take the names from a Notepad file, them through the arrays and then output them to a second Notepad file.
    Here is the original program: (view in full screen so that the code doesn't get jumbled)
    import java.io.*;       //Imports the Java library
    class progB                    //Defines class
        public static void main (String[] arguments) throws IOException
            BufferedReader keyboard;                                  //<-
            InputStreamReader reader;                                 //  Allows the program to
            reader = new InputStreamReader (System.in);               //  read the the keyboard
            keyboard = new BufferedReader (reader);                  //<-
            String name;                 //Assigns the name variable which will be parsed into...
            int newnames;               //...the integer variable for the amount of names.
            int order = 0;              //The integer variable that will be used to set the array size
            String[] array;             //Dynamic array (empty)
            System.out.println (" How many names do you want to input?");   //This will get the number that will later define the array
            name = keyboard.readLine ();
            newnames = Integer.parseInt (name);                                         // Converts the String into the Integer variable
            array = new String [newnames];                                               //This defines the size of the array
            DataInput Imp = new DataInputStream (System.in);       //Allows data to be input into the array
            String temp;                                       
            int length;                                                                  //Defines the length of the array for a loop later on
                for (order = 0 ; order < newnames ; order++)                                //<-
                {                                                                           //  Takes the inputed names and
                    System.out.println (" Please input name ");                            //  gives them a number according to
                    temp = keyboard.readLine ();                                           //  the order they were inputed in
                    array [order] = temp;                                                  //<-
                for (order = newnames - 1 ; order >= 0 ; order--)                                //<-
                {                                                                                //  Outputs the names in the reverse 
                    System.out.print (" \n ");                                                   //  order that they were inputed
                    System.out.println (" Name " + order + " is " + array [order]);             //<-
                for (order = 0 ; order < newnames ; order++)                                  //<-
                    if (array [order].startsWith ("M") || array [order].startsWith ("m"))     //  Finds and outputs any and all
                    {                                                                         //  names that begin with M or m
                        System.out.print (" \n ");                                            //
                        System.out.println (array [order] + (" starts with M or m"));         //
                    }                                                                         //<-
                for (order = 0 ; order < newnames ; order++)                                            //<-
                    length = array [order].length ();                                                   //
                    if (length >= 5)                                                                    //  Finds and outputs names
                    {                                                                                  //  with 5 or more letters
                        System.out.print (" \n ");                                                      //
                        System.out.println ("Name " + array [order] + " have 5 or more letters ");      //<-
    }The notepad file contains the following names:
    jim
    laruie
    tim
    timothy
    manny
    joseph
    matty
    amanda
    I have tried various methods but the one thing that really gets me is the fact that i can't find a way to connect the names to the arrays. Opening the file with FileInputStream is easy enough but using the names and then outputing them is quite hard. (unless i'm thinking too hard and there really is a simple method)

    By "connect", do you just mean you want to put the names into an array?
    array[0] = "jim"
    array[1] = "laruie"
    and so on?
    That shouldn't be difficult at all, provided you know how to open a file for reading, and how to read a line of text from it. You can just read the line of text, put it in the array position you want, until the file is exhausted. Then open a file for writing, loop through the array, and write a line.
    What part of all that do you need help with?

  • Need Help with .nnlp File.............A.S.A.P.

    I'm having a problem also with my JNLP file. I have downloaded the program onto one computer and that computer is using j2re1.4.2_04
    The other computers I believe are all running j2re 1.4.2_05
    I'm not sure if that's make a difference, but on the computer with j2re 1.4.2_05 when going to the site where the .jnlp file is located, the application comes up and says Starting Application. After it gets to that screen it just stays there. I really need help with this as soon as possible.
    Here is my .jnlp file listed below:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp
      spec="1.0+"
      codebase="http://www.appliedsolutions.com/placewiz"
      href="Placewiz.jnlp">
      <information>
        <title>Placement Wizard 4.0</title>
        <vendor>Applied Solutions, Inc.</vendor>
        <homepage href="index.html"/>
        <description>Placement Wizard 4.0</description>
        <description kind="short">Short description goes here.</description>
        <offline-allowed/>
      </information>
      <resources>
        <j2se version="1.4+"/>
        <j2se version="1.3+"/>
         <j2se version="1.5+"/>
        <jar href="Placewiz.jar"/>
      </resources>
      <security>
          <all-permissions/>
      </security>
      <application-desc main-class="com/asisoftware/placewiz/loader/Exec">
    </jnlp>

    This was due to a change in 1.4.2_05
    the main class attribute
    main-class="com/asisoftware/placewiz/loader/Exec">is wrong - it should be:
    main-class="com.asisoftware.placewiz.loader.Exec">this didnt seem to mater before 1.4.2_05, but some change in java since then caused this bad class specification to stop loading.
    /Andy

  • Need help with reading XML using File Adapter

    I have created a simple BPEL process that uses a file adapter to read files containing XML messages of a simple xsd schema. But when reading the xml, I get the following error message:
    [2010/03/01 23:43:13] Invalid data: The value for variable "Receive_1_Read_InputVariable", part "revision-report" does not match the schema definition for this part.The invalid xml document is shown below: More...
    [2010/03/01 23:43:13] "{http://schemas.oracle.com/bpel/extension}invalidVariables" has been thrown. less
    -<invalidVariables xmlns="http://schemas.oracle.com/bpel/extension">
    -<part name="code">
    <code>
    9710
    </code>
    </part>
    -<part name="summary">
    <summary>
    Invalid xml document.
    According to the xml schemas, the xml document is invalid. The reason is: Error::cvc-complex-type.4: Attribute 'doc' must appear on element 'revision-report'.
    Error::cvc-complex-type.4: Attribute 'model' must appear on element 'revision-report'.
    Error::cvc-complex-type.4: Attribute 'pubdate' must appear on element 'revision-report'.
    Error::cvc-complex-type.2.4.b: The content of element 'revision-report' is not complete. One of '{"http://xmlns.oracle.com/xmlfile":alternategroup}' is expected.
    Please make sure that the xml document is valid against your schemas.
    </summary>
    </part>
    </invalidVariables>
    It seems that there is some issue with the namespace, but even after trying out various combinations, I am not able to resolve this.
    Here the message schema (xsd):
    <?xml version="1.0" encoding="UTF-8" ?>
    <xs:schema elementFormDefault="qualified"
    targetNamespace="http://xmlns.oracle.com/xmlfile"
    xmlns:tns="http://xmlns.oracle.com/xmlfile"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="revision-report">
    <xs:complexType>
    <xs:sequence maxOccurs="unbounded">
    <xs:element name="alternategroup">
    <xs:complexType>
    <xs:attribute name="name" use="required" type="xs:string"/>
    <xs:attribute name="Desc" use="required" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    <xs:attribute name="doc" use="required" type="xs:string"/>
    <xs:attribute name="model" use="required" type="xs:string"/>
    <xs:attribute name="pubdate" use="required" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    And here is the xml file to be read by the file adapter:
    <?xml version="1.0" encoding="UTF-8" ?>
    <revision-report doc="doc2" model="model4" pubdate="pubdate5">
    <alternategroup Name="ABC" Desc="ABC-Desc">
    </alternategroup>
    <alternategroup Name="DEF" Desc="DEF-Desc">
    </alternategroup>
    <alternategroup Name="GHI" Desc="GHI-Desc">
    </alternategroup>
    </revision-report>
    Appreciate any help.
    Thanks in advance for your attention.
    Jay

    Thanks for your response.
    I am not sure if there is any easier way, but I tried out the following tool available on the net to check an xml against a xsd:
    http://tools.decisionsoft.com/schemaValidate/
    There were a few issues, that I corrected and finally had a xsd and xml that were matching and valid. I tried this out in my file reading BPEL process, but the error still remained the same!
    Here is my updated/simplified xsd and xml:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xs:schema targetNamespace="http://xmlns.oracle.com/xmlfile"
    xmlns:tns="http://xmlns.oracle.com/xmlfile"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://xmlns.oracle.com/xmlfile">
    <xs:element name="revision-report">
    <xs:complexType>
    <xs:sequence>
    <xs:element maxOccurs="unbounded" ref="alternategroup"/>
    </xs:sequence>
    <xs:attribute name="doc" use="required" type="xs:string"/>
    <xs:attribute name="model" use="required" type="xs:string"/>
    <xs:attribute name="pubdate" use="required" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="alternategroup">
    <xs:complexType>
    <xs:attribute name="Name" use="required" type="xs:string"/>
    <xs:attribute name="Desc" use="required" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    <?xml version="1.0" encoding="UTF-8" ?>
    <revision-report doc="doc2" model="model4" pubdate="pubdate5" xmlns="http://xmlns.oracle.com/xmlfile">
    <alternategroup Name="ABC" Desc="ABC-Desc"/>
    <alternategroup Name="DEF" Desc="DEF-Desc"/>
    <alternategroup Name="GHI" Desc="GHI-Desc"/>
    </revision-report>
    I even tried the option that is available in JDeveloper to generate a sample xml from a xsd (when in the context of a Transformation activity). The xml generated by this also seems exactly like the one above.
    So, I am not able to figure out why my BPEL process errors out with the message Invalid xml document.

  • I need help with viewing files from the external hard drive on Mac

    I own a 2010 mac pro 13' and using OS X 10.9.2(current version). The issue that I am in need of help is with my external hard drive.
    I am a photographer so It's safe and convinent to store pictures in my external hard drive.
    I have 1TB external hard drive and I've been using for about a year and never dropped it or didn't do any thing to harm the hardware.
    Today as always I connected the ext-hard drive to my mac and click on the icon.
    All of my pictures and files are gone accept one folder that has program.
    So I pulled up the external hard drive's info it says the date is still there, but somehow i can not view them in the finder.
    I really need help how to fix this issue!

    you have a notebook, there is a different forum.
    redundancy for files AND backups, and even cloud services
    so a reboot with shift key and verify? Recovery mode
    but two or more drives.
    a backup, a new data drive, a drive for recovery using Data Rescue III
    A drive can fail and usually not if, only when
    and is it bus powered or not

  • Need help in reading file, got stuck

    The code below works sometimes sometimes gives a message problem finding/reading file
    public void readData()
    try
    DataInputStream dataIn = new DataInputStream(new FileInputStream("c://suneetha//data.txt"));
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    goal[j] = (dataIn.readInt());
    dataIn.close();
    catch (IOException e){ System.out.println("problem finding/reading file");}
    catch (NumberFormatException nfe) { System.out.println("problem with format"); }
    public void writeData()
    int i=0,j=0;
    InputStreamReader is = new InputStreamReader( System.in );
    // Wrap input with a BufferReader to get
    // the readln() method to read a whole line at once.
    BufferedReader br = new BufferedReader( is );
    try {
    DataOutputStream dataOut = new DataOutputStream(new FileOutputStream("c://suneetha//data.txt"));
    System.out.println("enter the array:");
    String s = br.readLine(); // Read the whole line
    st = new StringTokenizer(s);
    // With tokenizer nextToken() method we can ignore
    // any beginning and trailing white space.
    for(j=0;j<9;j++)
    i=Integer.parseInt(st.nextToken());//Convert string to int
    System.out.println( "got: " + i );
    j=i;
    dataOut.writeInt(j);
    catch (IOException ioe) {
    System.out.println( "IO error:" + ioe );
    not knowing what the problem is!!!
    some times it accepts data from file(for reading) some times it wont.
    I don't thing there is any problem with writing to the file
    Any help is greatly appreciated
    Thanks
    Suneetha.

    Are you not posting this for third time ( and with same problems.)
    Anyways.....
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    goal[j] = (dataIn.readInt()); // ????You want them in a 2 d array ?then make goal
    int [][] goal = new int[3][3];
    And
    // use
    if( dataIn.available() > 0 ){
    goal[ i ][j] = dataIn.readInt();
    else{
      // Your "custom" messages
    }

  • Need help with backup files made by HP Recovery.

    So in 2011 I had made a post about a DV9 series HP laptop I had that I felt needed a harddrive. Well the laptop has been sold to a friend of mine and he has since fixed the issue it had. My curent deboggle is trying to deal with the 36GB of data it backed up onto an external USB powered harddrive. The information was saved from a system that ran Windows VISTA, on that same DV9 Pavilion. I have a new laptop and it's a Pavilion DV6 running windows 7. Is there some sort of 3rd party application or an uncommon HP utility that can open, run or modify. Specificaly I need to some files but not all, but if my only option is to extract all then that would be fine also. There is an executible in the backup folder but it doesn't extract anything it just locks up. 
    For the TLR portion, need to access backup files made on an older HP laptop with windows vista to a newer HP latop running windows 7.

    Terribly sorry for the post, I should have researched more before posting. I found the answer to my issue in another thread here on the HP forums! Thanks so much!!

  • Need help with .avi files

    Hi everyone. I just got an iMac for Christmas. I've been a PC user all my life, so I'm new to some of this stuff. My question is about .avi movie clips.
    I have a Casio Exilim digital camera. As soon as I set up my iMac I uploaded all data from my digital camera. I have several short movie clips in iPhoto. I can hear the audio, but I don't see video. How can I watch the videos on my new computer and use iMovie.
    Thanks in advance for your help!

    AVI is a container type, a container can contain any number of audio and video compression types, some of which may be editable and some not, some of which may be compatible with imovie and some not.
    QT Pro (and a number of other 3rd party applications) may help you convert these files to an appropriate format. It would help if we knew what compression types are used, you can determine this by opening the movie in QT and choosing inspector from the window menu.
    AVI is a very old MS proprietary format, it was even abandoned by MS over 10 years ago, unfortunately there is a small possibility AVI files can contain long forgotten compression types which there are no converters for, although since your files are from a modern camera this is quite unlikely.
    Report back with the compression types and someone will help further.

  • Need help with read/write to MODBUS RTU registers in Labview 8.0

    I’m trying to write and read the registers in G3800xx016. controlling temperatures and lightning.  Please look at the attached pdf file for this unit..
    I have used Lookout for about three years, and it works fine.. Now I want to expand my system and try to use Labview 8.0
    My temperature register start adress is 100 Hex  (256 dec) I read from Register with Function code 03.
    This register have values from 0-255 witch mean in labview for me as unsigned byte U8
    I read my temperature from the register like this: eks.: 40257 lets say value=5
    Slave    FC       Start Adress     Byte     Value               CRC
    01        03        0100                02        0005                7847   
    This is the status received from the Modbus tester when I use null-modem connection..
    I receive the same value if I use Modscan32
    I have used null-modem cable to read out the values.
    I have also PIR detectors that control movements and light of and on, and I read these starts at 40017.1
    01   03     0010     02    
    The register to switch on and of heating and lights starts at 404097.1  FC16  
    Values mention here is read from Lookout 5.0  
    I have tried examples and read for weeks about this, but everything stops when I try to use Labview 8.0    I can’t read any values from my Master unit, neither write to it, or read any values in Modbus testers when I use null-modem cable.. I have tried different baud rates in my serial connection and it works perfect in Lookout, but Not Labview..
    I have even bought DSC module, but I can’t write to either com ports or Modbus testers..
    Please anybody… is there anybody that can give me help with this??
    Start address for for PIR detectors is 40017.1 (FC03)  and for writing bits for on of to light and heatsystem is 404097.1 (FC16)
    I would be very happy for any idea that can give me some positive results…  Look at the attached pdf file.
    Thanks.. and very best regards from
    Benjii…
    Attachments:
    G3800x016_02-2005_eng.pdf ‏70 KB

    Hi... and thanks for your answer..
    Yes, I have downloaded the NI Modbus drivers.. I have downloaded that one + a lot of other things about Modbus..
    I have also tried communication between lokout and labview true null-modem cable.. and it works..
    I have tried several Modbus examples and I communicate with most of them with null-modem cable.
    I write to the right registers as well, cause I use Modbus scanner to read the information..
    I have used the same settings for serial communication as my Master device use, bust still I can't get any response..
    There was an error message in one of my example from the Modbus INIT module.. Maybe I should try to set up a new connection using VISA ??
    Maybe the problem is to INIT my serial port? I have tried restarting my computer after closing my system..  But still, I have the same problem..
    I hope you can give me any idea...
    Thanks again..  by the way.. is it possible to write and read directly to serial port with the DSC module??  If so.. how?? 
    Very best regards..
    Benjii..

  • Need help with fla.file

    Hi!
    I'm always having trouble with a fla.file in cs3 professional. Every time i try to reopen the file in flash i get this:
    failed to open document/users.desktop/jason/social.fla
    pls help reopen this file
    jay

    create a new directory and move your fla there and try and open.  if that fails, change the file's name and try and reopen.  if that fails and you created the fla, it's probably corrupt.

  • Need help with copying files onto external drive

    I need help! Trying to copy downloaded movie files from Vuze (which have downloaded successfully) and copy onto external hard drive to view them but it wont let me copy over to the external device. Any ideas how to fix this please???

    Can you explain the steps you used, and the error message (or symptom), that says the copy did not work? 

  • Need help with batch file for javac.exe and java.exe

    I have this in my batch file:
    c:\jdk1.3.1_05\bin\javac
    What symbol do I need to be able to run this from cprompt with any file following it

    Thanks could remember that for nothing

  • Need help with reading a file

    Hello, I'm trying to read this file, but I keep getting a java.nullpointerexception at the end of it:
    Element: PART
    Content: (HEADER,CHAPTER+)
    Element: p
    Content: (#PCDATA)
    Element: INTRODUCTION
    Content: (HEADER,p+)+
    Element: CHAPTER_NUMBER
    Content: (#PCDATA)
    Element: HEADER
    Content: (#PCDATA)
    Element: BOOK
    Content: (OPENER,SUBTITLE?,INTRODUCTION?,(SECTION|PART)+)
    Element: SECTION
    Content: (HEADER,p+)
    Element: CHAPTER
    Content: (CHAPTER_NUMBER,CHAPTER_TEXT)
    Element: OPENER
    Content: (TITLE_TEXT)*
    Element: CHAPTER_TEXT
    Content: (p)+
    Element: SUBTITLE
    Content: (#PCDATA)
    Element: TITLE_TEXT
    Content: (#PCDATA)
    here is my code:
                           s = br.readLine();
                            while (s != null){
                                    node[i] = new Node();
                                    if (s.startsWith("Element: ")){
                                       node.element = s.substring(s.indexOf(":") + 2);
    System.out.println("Element[" + i + "]: " + node[i].element);
    else if (s.startsWith(" Content: ")){  
    node[i].content = s.substring(s.indexOf(":") + 2);
    System.out.println("Content[" + i + "]: " + node[i].content);
    s = br.readLine();
    if (s.startsWith("Element: ")) i++; //line 194 causes error
    br.close();
    here is my output
    Element[0]: PART
    Content[0]: (HEADER,CHAPTER+)
    Element[1]: p
    Content[1]: (#PCDATA)
    Element[2]: INTRODUCTION
    Content[2]: (HEADER,p+)+
    Element[3]: CHAPTER_NUMBER
    Content[3]: (#PCDATA)
    Element[4]: HEADER
    Content[4]: (#PCDATA)
    Element[5]: BOOK
    Content[5]: (OPENER,SUBTITLE?,INTRODUCTION?,(SECTION|PART)+)
    Element[6]: SECTION
    Content[6]: (HEADER,p+)
    Element[7]: CHAPTER
    Content[7]: (CHAPTER_NUMBER,CHAPTER_TEXT)
    Element[8]: OPENER
    Content[8]: (TITLE_TEXT)*
    Element[9]: CHAPTER_TEXT
    Content[9]: (p)+
    Element[10]: SUBTITLE
    Content[10]: (#PCDATA)
    Element[11]: TITLE_TEXT
    Content[11]: (#PCDATA)
    java.lang.NullPointerException
    at Test.readDTDObjectFile(Test.java:194)
    at Test.<init>(Test.java:143)
    at Test.main(Test.java:338)
    can anybody help me figure out how to fix this? thanks so much!

    nevermind, i figured it out. thanks anyway!

  • Need help with reading a midi file!!!

    I want to be able to make a java program that can read midi files. I need to know what notes are played and when. how can i do this.
    A bit of code would be nice to to use as a resource.
    thnx

    http://java.sun.com/products/java-media/sound/
    There are links to code samples and maybe a tutorial

  • Need help with a file i am trying to print

    i try to print this file using adobe reader with all updates and it says
    can not print pdf
    it is trying to flatten the file before the print
    it still sends it to the printer but my boss says it should not give us an error message
    please help me
    https://www.dropbox.com/s/8ts56kjul4o3ygk/13-118%20IP%202013-11-8.pdf

    You don't need an Event Structure, a simple State Machine would be more appropriate.
    There are many examples of State Machines within this forum.
    RayR

Maybe you are looking for