473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

parsing files in applets

9
how to upload a xls or txt file and parse the same using java applets???
Jun 19 '06 #1
1 1534
D_C
293 100+
Careful. For security reasons, Java applets don't let you read files.

It is possible, but there are some hoops that need to be jumped through. I ran into this problem during the end of the semester of a group project. We did not have the time to figure it out.

I have some old code from that project I can post here. If you can figure it out, great. This reads a text file into a String array, each line of text getting it's own entry.

Expand|Select|Wrap|Line Numbers
  1.    public String[] readFile(String fileName)
  2.    {
  3.       String file = "";
  4.       String temp;
  5.  
  6.       String[] lines = new String[1];
  7.       String[] moreLines = new String[0];
  8.       int INDEX = 0;
  9.  
  10.       try
  11.       {
  12.          FileReader fr = new FileReader(fileName);
  13.          BufferedReader br = new BufferedReader(fr);
  14.          do
  15.          {
  16.             temp = br.readLine();
  17.             if(temp == null)
  18.                break;
  19.             else
  20.             {
  21.                if(INDEX == lines.length)  // add more entries, could make a subroutine but
  22.                {                          // this should be the only code that needs this.
  23.                   moreLines = new String[1+(int)(lines.length*1.618)];
  24.                   System.arraycopy(lines,0,moreLines,0,lines.length);
  25.                   lines = moreLines;
  26.                }
  27.                lines[INDEX++] = temp;
  28.             }
  29.          } while(true); // do
  30.       }
  31.  
  32.       catch (FileNotFoundException fnfe)
  33.       {
  34.          System.err.println("The file " + fileName + " was not found.");
  35.       }
  36.  
  37.       catch (IOException ioe)
  38.       {
  39.          System.err.println("There is an error in the file.");
  40.          // file.length() should be 0
  41.       }
  42.  
  43.       catch (Exception e)
  44.       {
  45.          System.out.println("An unknown error occurred.");
  46.          System.out.println(e);
  47.       }
  48.  
  49.       moreLines = new String[INDEX];
  50.       System.arraycopy(lines,0,moreLines,0,INDEX);
  51.       return moreLines;
  52.    }
Jun 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: SomeDude | last post by:
Hi, I have a question on file writing. I am not very experienced in Java programming. My hobby right now is to write an applet where 2 persons could play Go together (it is a board game). The...
1
by: Justin | last post by:
Hi, We are researching options on which technologies to use for an advanced web application. We are planning on using DHTML as much as possible, but there are a few components that require more...
1
by: Vincent Montressor | last post by:
I'm playing around with writing my own panel applets, and I'm trying to figure out how to get my panel applets to be restored when I log in. As an experiment, I'm using the simple clock applet...
8
by: Andreas Røsdal | last post by:
Hi, Is there such a thing as python applets for web browsers? (eg. such as java applets?) I think that could be useful. Andreas R.
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
7
by: Wayne Gibson | last post by:
Hi, I need some advise with a java applet. I am nearing completing of the project and am getting a little concerned how long it is taking for the applet to load. I have developed the java applet...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
0
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. I have used resource files and xnlLanguage to control the language displayed in a Motif application. Simply dropping an...
0
by: praveen2gupta | last post by:
Hi I would like to seek help in Applets using Java Media Framework for displaying video files. Any Link / code for this type of application will be appreciated.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.