Reading Text File From Server

Reading Text File From Server

Question:
I know I can’t read files from a local machine through my browser, but I can’t seem to read a file off my originating server either. There’s a way to do this, right?

Is there an example of reading a text file from my server and displaying it ? one that will run from a browser?

Answer:
The example below worked with Java Runner and Netscape.The main drawback is its inability towrite back to the file. Unfortunately, URLs don’t haveassociated output streams for this. To read andwrite to fileson the source host, you must implement a serverto which applets can send read and write requests.

import java.awt.*;import java.applet.*;import java.net.*;import java.io.*;public class Reader extends Applet {   private TextField path;   private ErrorFrame f = new ErrorFrame();   URL source;   TextArea display = new TextArea(8, 40); // 8 lines x 40 chars   String next;   AppletContext context;   public void init() {      setBackground(Color.pink);      add(path = new TextField(“”, 30));      add(new Button(“HIDE FILE”));      add(display);      context = getAppletContext();   }   public boolean action(Event e, Object arg) {            if (e.target == path) {         try {            String file = path.getText();            source = new URL(getCodeBase(), file);                     DataInputStream in = new DataInputStream(source.openStream());            // erase display            display.setText(“”);            while(null != (next = in.readLine()))               display.appendText(next + ”
“); in.close(); } catch(IOException ioe) { // f.error(ioe); my error dialog } } else if (arg.equals(“HIDE FILE”)) { display.setText(“”); return true; } return false; }}

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several