Applet:file writing?
this will be a very easy question for all the pros here:
i want to write a file that is on the server and in the same directory as the file!
thanks in advance
yes thats php!Yes it is.
now i tried it with filewriter!but it didnt work!What the f*** is filewriter?
And yes of course it works ('tut')
that can't be soo difficult!the file is on the server!It is with an applet, yes.
or even a servletimport java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class counter2 extends HttpServlet {
int count;
public void init() throws ServletException {
FileReader fr = null;
BufferedReader bfr =null;
try {
fr = new FileReader("InitDestroyCounter.initial");
bfr = new BufferedReader(fr);
String initial =bfr.readLine();
count = Integer.parseInt(initial);
return;
catch(Exception ignoreAll){}
finally {
try {
if(bfr != null){
bfr.close();
catch(Exception ignoreAll){}
String initial = getInitParameter("initial");
try {
count = Integer.parseInt(initial);
return;
catch(Exception ignoreAll){}
count =0;
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
count++;
out.println("Since loading the servlet has been accessed "+count+" times.");
public void destroy(){
super.destroy();
saveState();
public void saveState() {
FileWriter fwr = null;
PrintWriter pwr =null;
try {
fwr = new FileWriter("InitialDestoyCounter.initial");
pwr = new PrintWriter(fwr);
pwr.println(count);
return;
catch(Exception ignoreAll){}
finally {
if(pwr != null) {
pwr.close();
}php is the IDEAL tool for what youre trying to do
Go get 'em tiger!
Similar Messages
-
Applet file writing without permission
Is it possible for an applet to write a text or html document to be displayed in a browser without needing to grant it permissions?
I experimented with writing a file and naming the file to the directory that the applet's in using getCodeBase(), but that didn't work. I've been looking into writing directly to a browser, but that's kind of ugly, and it looks like you have to play with system paths and what-not in order to talk to javascript, so I ruled that out. Any help is appreciated.
-
Description:
A specific group of users/customers (using Windows7 OS with IE and FireFox web browsers) are facing problems with retrieving the applet File, after they upgraded the JRE on the system(PC) to JRE 1.7.0_25-b17 from JRE version 1.6.0_29-b11.
With JRE 1.7.0_25-b17 it is noticed that when the Java plugin requests for the applet File; it sends a request to the Domain Controller of the user, which causes a delay of 2 to 5 minutes and sometimes hangs. The problem occurs consistently.
The current temporary workaround for this group of users is to use JRE version 1.6.0_29-b11.
Problem analysis:
To investigate the problem the below steps were executed:
1) Collected the Java console outputbelow details from the user's system. (The complete output is not posted due to lengthy content, though can be added further to this post if required.)
(a) Works fine with JRE version 1.6.0_29-b11. Kindly refer to Java console output in the code ‘section A’ towards the end of this post.
(b) The problem occurs with problem with JRE version 1.7.0_25-b17. Kindly refer to Java console output in the code ‘section B’ towards the end of this post. The step where the problem is observed, is indicated as(##<comment>##).
2) The network settings in the user's browser was checked. Internet Options > Connections > LAN setting
The configured option is 'Use automatic configuration script' and the value is http://www.userAppX.com/proxy.pac
This configuration remains the same irrespective of the JRE version in use.
3) The network settings in the Java Control Panel was checked.
The used/selected option is "Use browser settings", although values for 'Use proxy server' and 'use automatic proxy configuration script' are filled-in as 'user-proxy.com' and 'http://www.userAppX.com/proxy.pac' respectively.
This configuration remains the same irrespective of the JRE version in use.
4) The proxy PAC file was checked and debugging was done for the request 'https://myAppletHost.com/download/...'. The FindProxyForUrl function (including the conditions defined in it, for the hostname and domain checks) returns PROXY user-proxy.com:80
5) The user also tried the below
a. Changed the option in the network settings in the browser to 'Proxy server' with Address 'user-proxy.com' and Port '80'
b. Restarted the browser.
c. Tried with Java Plug-in 1.6.0_29, JRE version 1.6.0_29-b11. There was no problem and no request to the Domain Controller of the user.
d. Tried with Java Plug-in 10.40.2.43, JRE version 1.7.0_40-b43. The problem occurs with the delay and a request to the Domain Controller of the user is observed.
Kindly refer to Java console output in the code ‘section C’ towards the end of this post.
6) The user also tried setting the below property in the Java Control panel; restarted the browser, and try with JRE 1.7.0_40-b43. The problem stil persists.
-Djava.net.preferIPv4Stack=true
7) The Global Policy Management of the Domain Controller was verified by the user. It has GPO for proxy setting but nothing related to Java security.
Questions:
The problem seems be specific to a particular (user) environment setup, and the user faces the problem when using JRE 1.7.
We would like to know if the issue is in the (user) environment setup or in JRE 1.7.
Could you please help with information/ideas/suggestions to identify the root cause and solution for this problem?
Section A:
Java Plug-in 1.6.0_29
Using JRE version 1.6.0_29-b11 Java HotSpot(TM) Client VM
User home directory = C:\Users\userA
basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-b1bb5056c5b0e83f=2; Path=/"
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-b1bb5056c5b0e83f=2; Path=/"
security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Internet Explorer ROOT certificate store
security: Loaded certificates from Internet Explorer ROOT certificate store
security: Checking if certificate is in Deployment denied certificate store
network: Connecting https://myAppletHost.com/download/myApplet.jar with cookie "JSESSIONID=0000IK4bEMoqXH10zsl88rwvoRI:175oe9tjd; BCSI-CS-b1bb5056c5b0e83f=2"
network: Downloading resource: https://myAppletHost.com/download/myApplet.jar
Content-Length: 403.293
Content-Encoding: null
Dump system properties ...
https.protocols = TLSv1,SSLv3
java.vm.info = mixed mode, sharing
java.vm.name = Java HotSpot(TM) Client VM
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.vendor = Sun Microsystems Inc.
java.vm.specification.version = 1.0
java.vm.vendor = Sun Microsystems Inc.
java.vm.version = 20.4-b02
javaplugin.nodotversion = 160_29
javaplugin.version = 1.6.0_29
javaplugin.vm.options =
os.arch = x86
os.name = Windows 7
os.version = 6.1
trustProxy = true
deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
deployment.proxy.bypass.local = false
deployment.proxy.http.host = user-proxy.com
deployment.proxy.http.port = 80
deployment.proxy.override.hosts =
deployment.proxy.same = false
deployment.proxy.type = 3
deployment.security.SSLv2Hello = false
deployment.security.SSLv3 = true
deployment.security.TLSv1 = true
deployment.security.mixcode = ENABLE
Section B:
Java Plug-in 10.25.2.17
Using JRE version 1.7.0_25-b17 Java HotSpot(TM) Client VM
User home directory = C:\Users\userA
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@12adac5
basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
(##THE ABOVE REQUEST CAUSES THE DELAY OR HANGS##)
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Internet Explorer ROOT certificate store
security: Loaded certificates from Internet Explorer ROOT certificate store
network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
network: Connecting https://myAppletHost.com/download/myApplet.jar with cookie "JSESSIONID=0000UQuXWY5tjxjpwcKHlfJKe_8:175oe9j45; BCSI-CS-2d4ce94a2ae7b460=2"
network: ResponseCode for https://myAppletHost.com/download/myApplet.jar : 200
network: Encoding for https://myAppletHost.com/download/myApplet.jar : null
network: Server response: (length: -1, lastModified: Thu Feb xx yy:yy:yy CET 2013, downloadVersion: null, mimeType: text/plain)
network: Downloading resource: https://myAppletHost.com/download/myApplet.jar
Content-Length: -1
Content-Encoding: null
Section C:
Java Plug-in 10.40.2.43
Using JRE version 1.7.0_40-b43 Java HotSpot(TM) Client VM
User home directory = C:\Users\userA
basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-1d67c8b6508ca09c=2; Path=/"
network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
(##THE ABOVE REQUEST CAUSES THE DELAY OR HANGS##)
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklist
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklisted.certs
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/baseline.version
network: Connecting https://javadl-esd-secure.oracle.com/update/blacklist with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Connecting https://javadl-esd-secure.oracle.com/update/baseline.version with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Connecting https://javadl-esd-secure.oracle.com/update/blacklisted.certs with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
Dump system properties ...
https.protocols = TLSv1,SSLv3
java.vm.info = mixed mode, sharing
java.vm.name = Java HotSpot(TM) Client VM
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.vendor = Oracle Corporation
java.vm.specification.version = 1.7
java.vm.vendor = Oracle Corporation
java.vm.version = 24.0-b56
javaplugin.nodotversion = 10402
javaplugin.version = 10.40.2.43
os.arch = x86
os.name = Windows 7
os.version = 6.1
trustProxy = true
active.deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
active.deployment.proxy.bypass.local = false
active.deployment.proxy.http.host = user-proxy.com
active.deployment.proxy.http.port = 80
active.deployment.proxy.same = false
active.deployment.proxy.type = 3
deployment.browser.path = C:\Program Files (x86)\Internet Explorer\iexplore.exe
deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
deployment.proxy.bypass.local = false
deployment.proxy.http.host = user-proxy.com
deployment.proxy.http.port = 80
deployment.proxy.override.hosts =
deployment.proxy.same = false
deployment.proxy.type = 3
deployment.security.SSLv2Hello = false
deployment.security.SSLv3 = true
deployment.security.TLSv1 = true
deployment.security.TLSv1.1 = false
deployment.security.TLSv1.2 = false
deployment.security.authenticator = true
deployment.security.disable = false
deployment.security.level = HIGH
deployment.security.mixcode = ENABLE
PS:
Since the JRE 1.7.0_25-b17 update, it is noticed that when the Java plugin requests for the applet File; it sends a request to the Domain Controller of the user, which causes a delay of 2 to 5 minutes and sometimes hangs.
The problem occurs consistently, and also with JRE 1.7.0_45-b18.
Java Plug-in 10.45.2.18
Using JRE version 1.7.0_45-b18 Java HotSpot(TM) Client VM
User home directory = C:\Users\userA
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
cache: Initialize resource manager: com.sun.deploy.cache.ResourceProviderImpl@134a33d
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@1971f66
basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-f797d4d262467220=2; Path=/"
network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
(##THE ABOVE REQUEST CAUSES THE DELAY AND SOMETIMES HANGS##)My organization is experiencing very similar problems. We have resolved it through several steps.
We upgraded the client to Java 8 and we saw in the console that the hanging connection with the Domain Controller no longer occurs. This may be all that is necessary for your environment as well. -
Hai
give some solution to find correct path using applet
below give is the applet code ,when i run this using IE ,path found is to be incorrect ,how to solve this problem
import java.io.*;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
/*<applet code ="Appdemo" width=300 height =50>
</applet>
public class Appdemo extends Applet
public void start()
java.io.File file1=new java.io.File("Screen.java");
System.out.println(" Path "+file1.getAbsolutePath());
JOptionPane.showMessageDialog(null,"path1"+file1.getAbsolutePath());
The above is the applet file
when i run this applet by
appletviewer Appdemo.java i am getting the correctpath as (D:\sample\Screen.java)
same thing when i run this applet in InternetEx
i am getting path as
c:\Document and setting\user\Desktop\Screen.java
how to solve this i need to get the same path as D:\sample\Screen.javaHi
I think in which directory yr screen...... file is present from where
u r running ur applet file
give the absolute path in file constructor
try this -
Please someone, help me,
Why when I'm trying to reinstall my OS, Tiger 10.4, at 56% of the installation, at files writing, it keeps on shutting off?Does it feel extra hot on top?
Are you reinstalling because you had several problems? If so what were they?
"Try Disk Utility
1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
*Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
3. Click the First Aid tab.
4. Select your Mac OS X volume.
5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
http://docs.info.apple.com/article.html?artnum=106214 -
I have to build a web application using servlet and jsp. The user should edit some
text file (maybe displaying the file fields in a HTML form).
I need some suggestions about implementing the synchronization on file writing (since different
users should try to save the same file simultaneously).
Do some standard pattern exist about this feature ?
I suppose to do that using a java bean whith application scope shared by the jsp pages. In this bean
I will implement all write methods using synchronized.
Any suggestions ?
Thanks in advance,
Mauro.well, if you have a single method which does the actual file writing, then you make that method synchronized and you'll have no problems. You can build up the data to write in some object at any time and pass that to that method.
However, that's still going to present problems when users actually modify the file at the same time. Why does every user have to share 1 file? -
Hi all,
I'm creating a simple app that gets form data and populates it to a file. I want to make sure that each instance (thread?) is able to write to the file and not throw an exception since the file may be currently open by another instance of the jsp. Now I did basic thread programming in C++ a long time ago, so I'm aware of thread waiting conceptually, but I'm not familiar with the java implementation. Can someone show me some basic syntax on how I would go in essentially putting a lock on the file writing portion of the code.
Thanx muchI disagree that you should override anything in Threa, especiially the sleep method.
What you should do is handle the file writing in a producer/consumer fashion. Have a single class that extends Runnable be the consumer. It handles all the file writing issues. You will run this in its own thread.
Your JSPs (or other threads) fill in a collection, or some other holder, which informs the consumer to write to the file.
As a brief example, this is a mini logger type of program. I use a class (LogCenter) to log data put in it from other sources (client1 and client2). For the sake of using newer API, I make use of the java.util.concurrent.BlockingQueue (and java.util.concurrent.LinkedBlockingQueue) to make a thread-safe collection and reporting system for text to come in and out of the logger.
Note, this is far from production. Just something I whipped up when playing with blocking queues a while ago...
package net.thelukes.steven.thread.test;
import java.io.PrintWriter;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class LoggingCenter implements Runnable {
private PrintWriter output;
private BlockingQueue<String> toPrint;
public LoggingCenter() {
toPrint = new LinkedBlockingQueue<String>(10);
public void setOutput(PrintWriter pw) {
if (pw == null) {
if (output != null)
return; //do not replace output with null
else //pw is null and output is null
throw new IllegalArgumentException("Ouput PrintWriter must not be NULL");
else {
if (output != null) closeOutput(); //if output exists already, close it.
output = pw;
public void log(String text) {
boolean added = false;
while (!added)
try {
toPrint.put(text);
added=true;
} catch (InterruptedException ie) {
ie.printStackTrace();
try { Thread.sleep(300L); }
catch (InterruptedException ie2) { ie2.printStackTrace();}
public void run() {
try {
while (true) {
printLn(toPrint.take());
} catch (InterruptedException ie) {ie.printStackTrace();}
private void closeOutput() {
output.flush();
output.close();
private void printLn(String text) {
if (output == null)
throw new IllegalStateException
("The Output PrintWriter must be set before any output can occur.");
output.println(text);
output.flush();
package net.thelukes.steven.thread.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class LoggingTest {
public static void main(String[] args) throws IOException {
PrintWriter output = new PrintWriter(
new FileWriter(new File("log.txt")));
//PrintWriter output = new PrintWriter(System.out, true);
final LoggingCenter logger = new LoggingCenter();
logger.setOutput(output);
Thread t = new Thread(logger);
t.start();
Thread client1 = new Thread(
new Runnable() {
public void run() {
while (true) {
logger.log("Client 1: "+System.currentTimeMillis());
try {
Thread.sleep(1250L);
} catch (InterruptedException e) {}
Thread client2 = new Thread(
new Runnable() {
public void run() {
while (true) {
logger.log("Client 2: "+System.currentTimeMillis());
try {
Thread.sleep(2500L);
} catch (InterruptedException e) {}
client1.start();
client2.start();
} -
File writing permissions??
is there any file writing permissions in jsp?
i can create folders with my code on my localhost Tomcat 5.5.
but now i have a webhost which has Tomcat 5.0...with my same jsp code i can see the content of my folders but cannot create any new folders under wwwroot or somewhere else on my webhost...
so i am thinking if it is related with permissions or something like that?please show me a way
thanks
Burakmy host admin responded;
Hi,
We can enable write permission, but this will put you in high security risk in tomcat shared hosting, as any other user also from his jsp/servlet script can write anything into your directory or delete file.
Now what you think?what i want to do is i have a photo album site...users can create their own folders and upload their photo albums...but this users' main folder must be somewhere in a protected area that users musnt directly link to this photos...like before wwwroot or after WEB-INF folder...where can it be?
please help me in this subject..need really help..
thanks -
Does UTL_FIL utility supports file writing in to remote Host ??
Hi,
I am checking the possibility with UTL_FIL utility whether supports file writing in to remote Host. My database is on different server from UNIX server but i want to make use of Oracle directory objects or UTL_FILES functions to be able to write files directly from Oracle to remote UNIX server.
Is this possible ?
Thanks
AnandUTL_FILE, and any other PL/SQL package running on the database server, can only access objects that the database server has access to. Unless the remote Unix server's file system is mounted from the Oracle server's file system, UTL_FILE would be unable to create a file there.
Now, there may well be alternateives. For example, you could generate the file locally and FTP the file to the remote Unix server, assuming the remote Unix server is running a FTP server.
Justin -
Hello, I have a problem with writing a file. My code is very simple..it takes a line from one file, a line from a second file, combines them, and writes them into the third file. However, the program never gets past the point where it creates the output file. Any help is appreciated.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MergeFiles extends JApplet implements ActionListener
private final String filename = "mergedfiles.txt";
BufferedReader f1in, f2in;
FileOutputStream outputstream;
JTextField f1f = new JTextField("file1.txt", 20);
JTextField f2f = new JTextField("file2.txt", 20);
String F1text, F2text, F3text;
JLabel title = new JLabel("Merge files program! Press enter to merge!");
JButton merge = new JButton("MERGE! MERGE! MERGE!");
JLabel labelone = new JLabel("File one");
JLabel labeltwo = new JLabel("File two");
Container con = getContentPane();
JPanel pane = new JPanel();
GridBagConstraints c = new GridBagConstraints();
public void makedisplay()
Insets i = new Insets(10, 10, 10, 10);
pane.setLayout(new GridBagLayout());
pane.setBackground(Color.green);
con.setBackground(Color.green);
con.add(pane, BorderLayout.CENTER);
con.add(title, BorderLayout.NORTH);
c.weightx = 0;
c.insets = i;
c.gridy = 0;
c.gridx = 0;
pane.add(labelone, c);
c.gridx = 1;
pane.add(labeltwo, c);
c.gridx = 0;
c.gridy = 1;
c.ipadx = 50;
pane.add(f1f, c);
c.gridx = 1;
pane.add(f2f, c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 3;
c.ipadx = 0;
pane.add(merge, c);
public void init()
makedisplay();
merge.addActionListener(this);
public void actionPerformed(ActionEvent e)
openfiles();
File f = new File("H://mergefiles//mergedfile.txt");
try {
title.setText("AAA");
BufferedWriter out = new BufferedWriter(new FileWriter(f));
F1text = f1in.readLine();
F2text = f2in.readLine();
title.setText("BBB");
F3text = "" + F1text + F2text;
out.write("" + F3text);
f1in.close();
f2in.close();
out.close();
catch (IOException ex)
public void openfiles()
try
BufferedReader f1in = new BufferedReader(new FileReader(f1f.getText()));
title.setText("file one opened");
catch (FileNotFoundException e)
title.setText("File one not found!");
try
BufferedReader f2in = new BufferedReader(new FileReader(f2f.getText()));
title.setText("File two opened");
catch (FileNotFoundException e)
title.setText("File two not found!");
}Nevermind, I've fixed the problem...for some reason you can't use the writer with an applet. I've written some new code that works:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MergeFiles2
static String F1L = "", F2L = "";
static File file1 = new File("H://mergefiles//file1.txt");
static File file2 = new File("H://mergefiles//file2.txt");
public static void main(String[] args) throws IOException
PrintWriter out = new PrintWriter(new FileWriter("file3.txt"));
BufferedReader f1in = new BufferedReader(new FileReader(file1));
BufferedReader f2in = new BufferedReader(new FileReader(file2));
while (F1L != null)
F1L = f1in.readLine();
if (F1L != null)
out.println(F1L);
while (F2L != null)
F2L = f2in.readLine();
if (F2L != null)
out.println(F2L);
out.close();
} -
File Writing - Missing some files without any error
I am executing the following code:
String message = XMLHelper.getDocumentXML(_doc);
File outFile = getFile();
RandomAccessFile raf = new RandomAccessFile(outFile, "rw");
FileChannel channel = raf.getChannel();
ByteBuffer buf = ByteBuffer.allocateDirect(19600);
buf.clear();
buf.put(message.getBytes());
buf.flip();
channel.write(buf);
channel.close();
raf.close();
This code is in a loop and it must write a lot of files. I am trying with 426 but thje problem i have is that many times i do get 425 files insted of 426 or some other times i do get 425 files. No error or exception is thrown. Other times id do get my 426 files.
The problem increase when i process like 50000 files, the quantity it is supposed to treat.
Please can any body tell me what happen with the missing files? How can i detect what is happening?
Thank you very much to any one who can help me with this extrange errorHard to tell based on the info you supplied. How are you generating filenames? Are you accidently writing over an existing ouput file? Can you post more code, speciifcally the loop code around the code below?
-
Problem in creating New line in --File writing(Urgent)
Hi all
I am facing a tipical problem.
I am writing a Text file using FileWriter and i am using "\n" for writing a new line,
but when i open notepad all are falling on a single line with a special char
(if i open the text file in some other editor vie wis very fine)
C-0-1@C-1-0@ C-2-1
@ is where i am writing new line.
but this king of writing is not supported by my third party tool to which i am sending the text file
as parameter..
Kindly any one provide me a solution.
Byenewlines differ between windows and linux/unix. Windows' new line character is somthing like "\n\m" where linux uses "/n". So to keep your program platform independent I would suggest using System.getProperty("line.separator") so your code might look like:
String s = "C-0-1" + System.getProperty("line.separator") + "C-1-0" + System.getProperty("line.separator") + "C-2-1";
//then write the string to the filethis will give you the appropriate newline character for the platform your program runs on. -
hi. i'm new to java (coupla weeks), and i want to write an applet that reads adn writes a server-side file. i can do this with an application no problem, but i think it doesn't work with my applet because of security issues.
i have an idea that maybe what i need to do is get the URL of the file, then open a connection to it and use Input/OutputStreams. am i on the right track?
also, to get the URL, can i just give it the name of the file, if the applet resides in the same directory?
any answers/ sample code dealing with URLs and file i/o would be extremely helpful. thanx ~LActually, you need to write a server-side application to do that for you... An applet cannot write to a file on the server (nor on your computer without signing it for that matter). Started to write a program but figured out that I didn't have time... But basically the point is that you can't directly use a URLOutputStream to write to a file... You need to create an application that runs on the computer that holds the file that will accept input and then write to a file.
GN
P.S. I can tell you that I certainly didn't get into this in my first couple weeks :) -
Applet file not found execption.. what to do ?
Hai to all ...
I have a created an japplet within a netbeans project (*NewJApplet*). This applet is used to display a spell checking jframe(*SpellerFrame*) which does all the spell checking part i need. The jframe I mentioned makes use of another class (*mySpellChecker)* which in turn requires an external library jar file (*jazzy-core.jar*). The mySpellChecker class also needs to access a dictionary file english.0 within a dict file which i placed in a folder (*dict*) in the root of the project. In the applet viewer the applet works fine. But when i try to embed the applet in an HTML page problems arise. After 'googling' for quite a bit i managed to solve many of the problems which were primarily related to Applet tag attributes.
I build the project using netbeans. In the dist folder i placed the html file i was talking about and all the external library jars which i explicitly declared in the applet tag.
But now i have a problem . In the browser the html page is displayed but the applet does not load. The applet console says the dict/english.0 file cannot be found
Could anybody help ?
Sorry for making the post too long[http://java.sun.com/docs/books/tutorial/deployment/applet/data.html] may be of some use.
-
Hi, I am new to applets and I am trying to build an applet that needs input from other files on the server. How can I give my applet access to these files? I found some code with URLConnection, but I cannot seem to make it work. I am getting AppletNotLoaded appearing on the bottom of the webpage. Here is some of the URLConnection code, if anyone knows of mistakes in it:
URL url;
URLConnection urlConn;
//DataInputStream cfile;
url = new URL(getCodeBase().toString() + "/R2Code/ourcode/data/"+filename+".con");
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
BufferedReader cfile = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
//BufferedReader cfile = new BufferedReader(new FileReader (filename+".con"));
cfile.readLine();
StringTokenizer st = new StringTokenizer(cfile.readLine());
I am trying to read in a text file, which has the ending ".con" if that concerned anyone. Any advice would be great, thanks.Here is the specific error from java console:
load: class ProteinApplet3.class not found.
java.lang.ClassNotFoundException: ProteinApplet3.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
I am also getting errors saying that certain classes cannot be found, like point3f or anything from vecmath. Is there something to be done to fix this?
It has to be finding the applet, just not loading it because its reading through the list of imports...
Maybe you are looking for
-
How do I move my library from Mac to Windows?
I moved my iTunes library to a Windows XP machine and put the library where it's supposed to be. Then I exported the library xml file on my Mac and imported it in Windows. When I open iTunes the library is empty. I tried importing the files into iTun
-
How run app for customers and how to send dunning notice to vendors
Hi experts. Can any one help on following issue with example scenarios. how run app for customers and how to send dunning notice to vendors
-
Using an aiport express + airport extreme for printing.
I have an airport extreme to which I connect a lexmark color laser printer. Everything works well. I just moved and am now using DSL. There is no phone jack in the room where I want to put my printer. Can I use the airport extreme for my wireless int
-
After Effects CS4 - Rendering and Locating Missing Files/Reconnecting Media
I am needing to do the following and unfamiliar as I am new to CS 4: 1. Rendering 2. Locating a missing file/reconnecting media Thanks, "scubakgd"
-
Here's the scenario: 1. Send IDoc to middleware 2. Middleware updates an external application database 3. If the database update is successful 4. Send acknowledgement back to SAP 5. IDoc status is updated (possibly status 41?) Is this possible? Middl