Read Text file using Java Script

Hi,
I am trying to read a text file using Java Script within the webroot of MII as .HTML file. I have provided the path as below but where I am not able to open the file. Any clue to provide the relative path or any changes required on the below path ?
var FileOpener = new ActiveXObject("Scripting.FileSystemObject");
var FilePointer = FileOpener.OpenTextFile("E:\\usr\\sap\\MID\\J00\\j2ee\\cluster\\apps\\sap.com\\xapps~xmii~ear\\servlet_jsp\\XMII\\root\\CM\\OCTAL\\TestTV\\Test.txt", 1, true);
FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
The Error Log shows as :
Path not found
Regards,
Mohamed

Hi Mohamed,
I tried above code after importing JQuery Library through script Tag. It worked for me . Pls check.
Note : You can place Jquery1.xx.xx.js file in the same folder where you saved this IRPT/HTML file.
<HTML>
<HEAD>
    <TITLE>Your Title Here</TITLE>
    <SCRIPT type="text/javascript" src="jquery-1.9.1.js"></SCRIPT>
    <script language="javascript">
function Read()
$.get( "http://ldcimfb.wdf.sap.corp:50100/XMII/CM/Regression_15.0/CrossTab.txt", function( data ) {
  $(".result").html(data);
  alert(data);
// The file content is available in this variable "data"
</script>
</HEAD>
<BODY onLoad="Read()">
</BODY>
</HTML>

Similar Messages

  • Read text file using Java(streamTokenizer)

    Hi, all,
    I am lost when trying to read data from a text file to a Java prgram. The text file looks like the following:
    106,62,2322,8159,1
    106,62,3658,8333,1
    106,62,4215,8334,2
    Each number is seperated by "," and each line representing one row of data. I was thinking about using streamTokenizer to read the data into a multi-dimentional array. Since I am new to Java and just read something about the streamTokenizer from book, I would like to get some help from someone who is more experienced with that.
    Thanks for your help!
    Kevin

    Hi Kevin,
    try this:
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;
    public class Answer {
            public static void main(String[] args) {
            List data = new ArrayList();
            try {
                BufferedReader in = new BufferedReader(new FileReader("...your text file ..."));
                String line;
                // reading the file line by line
                while ((line = in.readLine()) != null) {
                    // splitting the line into token
                    StringTokenizer st = new StringTokenizer(line, ",");
                    List row = new ArrayList();
                    while (st.hasMoreTokens()) {
                        row.add(new Integer(st.nextToken()));
                    data.add(row); // adding the row of data
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            // test result
            System.out.println(data);
    }I don't like to use arrays, because when I start reading the file, I don't know yet, how many rows of data it is containing. Therefore a java.util.List is much more convenient (you don't have to initialize). Your result is now a java.util.List containing elements of java.util.List containig elements of Integer.
    Harri

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

  • How to print a text file using Java

    How can I print a text file using Java without converting the output to an image format. Is there anyway I can send the characters in the text file as it is for a print job? I did get a listing doing this ... but that converted the text to an image format before printing....
    THanks,.

    Hi I had to write a print api from scratch, and I did not convert the output to image. Go and read up on the following code. I know there is a Tutorial on Sun about the differant sections of the snippet.
    private void printReport()
         Frame tempFrame = new Frame(getName());
         PrintJob printerJob = Toolkit.getDefaultToolkit().getPrintJob(tempFrame, "Liesltext", null);
         Graphics g = printerJob.getGraphics();
                    //I wrote the method below for calculations
         printBasics(g);
         g.dispose();
         printerJob.end();
    }This alone wont print it you have to do all the calculations in the printBasics method. And as I said I wrote this from scratch and all I did was research first the tutorial and the white papers
    Ciao

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

  • Changing HTML to text file using java

    Hi,
    I am doing a project in which i have to read news articles from websites. I have tried XML but for that i need to know which tag has the article in it. Since i have to read from various websites so each site used different tags for different informations.
    Is there anyway that i can change an HTML file into a text file using java. Maybe some command that removes all the HTML tags and gives just the information. Is there anything else that anyone would like to recommend?
    Thanx
    yafis

    Maybe something like this:
    import java.io.*;
    import java.net.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    class GetHTMLText
         public static void main(String[] args)
              throws Exception
              EditorKit kit = new HTMLEditorKit();
              Document doc = kit.createDefaultDocument();
              // The Document class does not yet handle charset's properly.
              doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
              // Create a reader on the HTML content.
              Reader rd = getReader(args[0]);
              // Parse the HTML.
              kit.read(rd, doc, 0);
              //  The HTML text is now stored in the document
              System.out.println( doc.getText(0, doc.getLength()) );
         // Returns a reader on the HTML data. If 'uri' begins
         // with "http:", it's treated as a URL; otherwise,
         // it's assumed to be a local filename.
         static Reader getReader(String uri)
              throws IOException
              // Retrieve from Internet.
              if (uri.startsWith("http:"))
                   URLConnection conn = new URL(uri).openConnection();
                   return new InputStreamReader(conn.getInputStream());
              // Retrieve from file.
              else
                   return new FileReader(uri);
    }

  • How to read pdf files using java.io package classes

    Dear All,
    I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block
    Thanks in advance.

    hi I also have the pbm. to read pdf file using JAVA
    can any body help meWhy is it so difficult to read the thread you posted in? They say: java.io is pointless, use iText. So why don't you?
    or also I want to read a binary encoded data into
    ascii,
    can anybody give me a hint how to do it.Depends on what you mean with "binary encoding". ASCII's binary encoding, too, basically.

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • To read text file using utl_file

    I would like to read test_file_out.txt which is in c:\temp folder.
    create or replace create or replace directory dir_temp as 'c:\temp';
    grant read, write on directory dir_temp to system;
    then when i execute the below code i get the error .
    // to read text file using utl_file
    DECLARE
    FileIn UTL_FILE.FILE_TYPE;
    v_sql VARCHAR2 (1000);
    BEGIN
    FileIn := UTL_FILE.FOPEN ('DIR_TEMP', 'test_file_out.txt', 'R');
    UTL_FILE.PUT_LINE (FileIn, v_sql);
    dbms_output.put_line(v_sql);
    UTL_FILE.FCLOSE (FileIn);
    END;
    ERROR:
    invalid file operation
    i would like to use ult_file only and also can you let me know to read the text file and place its contents in tmp_emp table?

    Are you trying to read the contents of the file into the local variable? Or write the contents of the local variable to the file?
    Your text talks about reading the file. And you open the file in read mode. But then you call the UTL_FILE.PUT_LINE method which, as SomeoneElse points out, attempts to write data to the file. Since the file is open in read-only mode, you cannot write to the file.
    If the goal is really to read from the file, replace the UTL_FILE.PUT_LINE calls with UTL_FILE.GET_LINE. If the goal is really to write to the file, you'll need to open the file in write mode ('W' rather than 'R' in the FOPEN call).
    Justin

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • How to replace a line ina text file using java?

    Hi ALL,
    Does anybody know how to replace a line in a text file uisng java.

    use this thing:
    http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    open the file,
    read its contents, replace the text you need in the contents, set the contents back into the file.
    it takes care of the IO for you.

  • Displaying of a text file using JAVA in a browser.

    Please can you give me the code for displaying of a text file using a bean and java coding. Please include all files needed. Thanks

    please could you give us 200 Uss each for the work done for you plz include all needed recipes plz? thx

  • Reading PDF file Using java.

    I tried to read the pdf file using FileInputStream. but it gives the Juncked charectars.
    How can i read(means content) the pdf file using Java.

    I just found the "Multivalent" library, it is free and will do exactly what you want: http://www.cs.berkeley.edu/~phelps/Multivalent/
    Check out the source of the tools/ExtractText.java file
    Ed

  • Can't read text file using UTL_FILE

    Hi All,
    how can I read notepad file using UTL_FILE package.I have specified the UTL_FILE_DIR in the init.ora file.My objective is to when a button is clicked, the contents of the file will display in a text item.Here is my code written in WHEN_BUTTON_PRESSED trigger.
    DECLARE
         file_handle UTL_FILE.FILE_TYPE;
    data_line Varchar2(100);
    BEGIN
         file_handle := UTL_FILE.FOPEN('E:\vimal','abc.txt','R');
              message('directory created');
         UTL_FILE.GET_LINE(file_handle, data_line);
         :block2.t1 := data_line;
         UTL_FILE.FCLOSE(file_handle);
    END;

    Why don't you use text_io? Don't forget that UTL_FILE is reading directories from the database point of view. The E drive for the database is a different E then on your client pc. I presume your database is on a different computer. Are you getting any errors?

  • Can't read a text file using java

    Hi All
    I am trying to read a log file.
    ProgramA keeps updating the log file, while my program ProgramB reads it.
    For some readson my ProgramB is not able to read the last two lines in the log file. If I run the program in debug mode it is reading all the lines.
    This is having me frustrated.
    Please let me know if there is a way to read entire contents.
    Here is how I am reading the files ( 2ways)
         private static String readFileAsString(String filePath)
        throws java.io.IOException{
            StringBuffer fileData = new StringBuffer(1000);
            FileReader fr = new FileReader(filePath);
            BufferedReader reader = new BufferedReader(fr);
            char[] buf = new char[1024];
            int numRead=0;
            while((numRead=reader.read(buf)) != -1){
                String readData = String.valueOf(buf, 0, numRead);
                fileData.append(readData);
                buf = new char[1024];
            reader.close();
            fr.close();
            return fileData.toString();
           * Fetch the entire contents of a text file, and return it in a String.
           * This style of implementation does not throw Exceptions to the caller.
           * @param aFile is a file which already exists and can be read.
           static public String readFileAsString(String filePath) {
             //...checks on aFile are elided
             StringBuffer contents = new StringBuffer();
             //declared here only to make visible to finally clause
             BufferedReader input = null;
             try {
               //use buffering, reading one line at a time
               //FileReader always assumes default encoding is OK!
               input = new BufferedReader( new FileReader(filePath) );
               String line = null; //not declared within while loop
               * readLine is a bit quirky :
               * it returns the content of a line MINUS the newline.
               * it returns null only for the END of the stream.
               * it returns an empty String if two newlines appear in a row.
               while (( line = input.readLine()) != null){
                 contents.append(line);
                 contents.append(System.getProperty("line.separator"));
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
             finally {
               try {
                 if (input!= null) {
                   //flush and close both "input" and its underlying FileReader
                   input.close();
               catch (IOException ex) {
                 ex.printStackTrace();
             return contents.toString();
           }

    If you're using JDK 5 or later, you could use the Scanner class for input information. See below:
    try {
                   Scanner reader = new Scanner(new File("C:\\boot.ini"));
                   StringBuilder sb = new StringBuilder();
                   while (reader.hasNextLine()) {
                        sb.append(reader.nextLine());
                        sb.append(System.getProperty("line.separator"));
                   System.out.println(sb.toString());
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              }

Maybe you are looking for

  • Database restore of Content and Cache Server on different SID

    Hi Experts, I am trying to do backup \ restore method, is it the correct way to do. if not, please suggest me the correct methodology. if yes, please let me know the procedure to restore the database on different SID Content Server and cache server w

  • Ignoring a target field in LSMW processing

    Hi All,         Is there a way to ignore a particular target field and its mapping in LSMW? For example, if there are 10 target fields present in a target structure, I want to ignore say 2 fields based on a value in file for another field so only 8 t

  • Is it possible to use same data source for two info cube

    Hi, My Problem is in BW we can not have value of material at storage location level.In R/3 also value is maintained at plant level. Then we searched and we found out one hot to doc for summarized display of stock values on storage location level. Pro

  • Unknown error (4251)

    Hi, I have been doing a lot of research all night on my problem and I see that not many people know how to get past it. The one person who posted that their problem was solved by using this forum. Anyway, when I tried to burn an audio book that I dow

  • Installed sync on Firefox 3.6.8. I receive error message: Server Incorrectly Configured. How to fix it?

    I installed Sync on Windows XP Home Edition, Firefox 3.6.8, with Zone Alarm and AVG anti-virus. Sync is not updating, instead it produces error message: Server Incorrectly Configured and hangs up. How to fix it?