473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read the directory from an applet

2 New Member
Hello,

I just would like to read a specific (/Downloads/) directory of the client machine in order to get the latest file:
My code look for text files like "quotes.txt , quotes-1.txt, ... quotes-42.txt etc..." and would like to point to the last one (quotes-42.txt).

I know that I will have to sign the applet later...

Right now I'm able to read a specific file (quotes.txt) but what if there is more in the sequence?

A loop, but how to get out of it?

Thank you much.
Apr 18 '07 #1
2 1410
JosAH
11,448 Recognized Expert MVP
Hello,

I just would like to read a specific (/Downloads/) directory of the client machine in order to get the latest file:
My code look for text files like "quotes.txt , quotes-1.txt, ... quotes-42.txt etc..." and would like to point to the last one (quotes-42.txt).

I know that I will have to sign the applet later...

Right now I'm able to read a specific file (quotes.txt) but what if there is more in the sequence?

A loop, but how to get out of it?

Thank you much.
Read all about it in the File class API documentation; pay special attention
to its list or listFiles methods.

kind regards,

Jos
Apr 18 '07 #2
dimitryous
2 New Member
Read all about it in the File class API documentation; pay special attention
to its list or listFiles methods.

kind regards,

Jos
Almost got it but...

Here is my code:
Expand|Select|Wrap|Line Numbers
  1.     public static void listDirectory( File the_Directory ) {
  2.         //System.out.println ("132: " + the_Directory.getAbsolutePath());
  3.         int max = 0;
  4.         String the_String = "quotes";
  5.         if ( the_Directory.isDirectory ( ) ) {
  6.                 File[] list = the_Directory.listFiles();
  7.                 if (list != null) {
  8.                     //System.out.println ("137: " + the_Directory.getAbsolutePath());
  9.                     for ( int i = 0; i < list.length; i++) {
  10.                             // recursive call to sub-directories if any
  11.                             listDirectory( list[i] );
  12.                     } 
  13.                 } else {
  14.                     System.err.println("Error reading directory: " + the_Directory);
  15.                 }
  16.         }
  17.         else {
  18.             String the_S_File = the_Directory.getAbsolutePath(); // got a file
  19.             String[] members = the_S_File.split("/");
  20.  
  21.             for ( int i = 0; i < members.length; i++) {
  22.                 if (members.length == 3 & i == 2) { // at the second level ?
  23.  
  24.                     // System.out.println( "quotes-39.txt".indexOf( the_String ) ); // 0
  25.                     if (members[2].indexOf( the_String ) == 0) { // like quotes-39.txt ?
  26.                         if (members[2].length() > the_String.length() + 4) { // live out quotes.txt
  27.                             //System.out.println(members[2]);
  28.                             String[] sub_members = members[2].split("-");
  29.                             for ( int j = 0; j < 2; j++) {
  30.                                 if (j==1) {
  31.                                     int the_pos = sub_members[j].indexOf(".");
  32.                                     String the_int_S = sub_members[j].substring( 0 , the_pos );
  33.                                     int k = Integer.parseInt( the_int_S , 10 );
  34.  
  35.                                     if ( max < k ) {
  36.                                         max = k; // bug here : max made a reset ***
  37.                                     }
  38.  
  39.                                     System.out.println( k + " " + max + " " + sub_members[j]);
  40.  
  41.                                 }
  42.                             }
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }
Don't get the max value out of it because of the recursive stuff...

Any idea?
Apr 19 '07 #3

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

Similar topics

1
3346
by: ParkPD | last post by:
Hi, I have been made a signed-applet that handling xml data from web-server. When I execute this applet with appletviewer, it works well. And it is OK with Internet Explorer. But when I opened this page with Netscape 7.0(OS is Windows XP sp1), this applet throw exception when reading xml data from web server. the error message is like this, "Exception : java.security.AccessControlException: access
0
9873
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ********************************** package Celcom.Client;
1
2944
by: Charlie Kim | last post by:
Here is gnome applet source of mine. -------------------------------------------------- #!/usr/bin/env python import pydic import gtk import gnome.applet
2
17641
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan all the files in the directory and select the one with the highest week number then display in the browser window. A brief search hasn't revealed any code to do this so I just want to know if it is possible and what the function names are that...
3
7289
by: SzokU | last post by:
Hi All! I have problem... I want to write/read value from param tag in applet, but I don't know how... This is exaple code: ---------------------------------------------------------------------------- <applet code="example.class"> <param name="font" value="Arial"> <param name="width" value="80"> <param name="image_url" value="http://some.url/image.gif"> </applet>
5
6337
by: Doug | last post by:
I would appreciate a response on this. I have clients who will be placing text files information about in a network directory for example: http://www.protegen.com/clients/ Is it possible to read these text files using either vbscript or javascript. What I am attempting to do is to read these files and then create charts for viewing by each client. A direct email to me at douglas.taylor@protegen.com will help.
1
2072
by: Roberto Gallo | last post by:
Hi, I have an applet running inside an html document and I need to read and to set some of html form's textfield and textarea input from my applet. How can I do that? Do I need a javascript? Thank you, Roberto Gallo
10
1697
by: slim_naldy | last post by:
I want to traverse to a client directory and show the clients directory and files. Is there a way without using the the <input> tag? I mean dynamically retrieving the directory information of the client browsing the web page?
1
3216
by: sandeepk84 | last post by:
Hi all... I am having an applet program for playing an audio file. It runs normally... but when it's run from browser, its showing the filepermission error. java.security.AccessControlException: access denied (java.io.FilePermission "filename" read) how to solve this? i have tried all the ways...tried changing the java.policy file by adding grant permission, etc. also i created a java.policy.applet file in my directory where the applet...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.