Creating a log in a text file

Ads
 

Creating a log in a text file

View Answers

October 3, 2008 at 4:11 PM

Hi,


import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.net.*;

public class AppletTextDemo extends Applet{
JButton write = new JButton("WriteToFile");
Label label1 = new Label("Enter the file name:");
TextField text = new TextField(20);
Label label2 = new Label("Write your text:");
TextArea area = new TextArea(10,20);
public void init(){
add(label1);
label1.setBackground(Color.lightGray);
add(text);
add(label2);
label2.setBackground(Color.lightGray);
add(area);
add(write,BorderLayout.CENTER);
write.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent e){
new WriteText();
}
});
}
public class WriteText {
WriteText(){
try {
String str = text.getText();
if(str.equals("")){
JOptionPane.showMessageDialog(null,"Please enter the file name!");
text.requestFocus();
}
else{
File f = new File(str);
if(f.exists()){
BufferedWriter out = new BufferedWriter(new FileWriter(f,true));
if(area.getText().equals("")){
JOptionPane.showMessageDialog(null,"Please enter your text!");
area.requestFocus();
}
else{
out.write(area.getText());
if(f.canWrite()){
JOptionPane.showMessageDialog(null,"Text is written in "+str);
text.setText("");
area.setText("");
text.requestFocus();
}
else{
JOptionPane.showMessageDialog(null,"Text isn't written in "+str);
}
out.close();
}
}
else{
JOptionPane.showMessageDialog(null,"File not found!");
text.setText("");
text.requestFocus();
}
}
}
catch(Exception x){
x.printStackTrace();
}
}
}
}

----------------------
<HTML>
<BODY>
<div align = "center">
<APPLET CODE = "AppletTextDemo.class" WIDTH = "500" HEIGHT = "400"></APPLET>
</div>
</BODY>
</HTML>

------------------------------------


Visit for more information.

http://www.roseindia.net/java/

Thanks

Ads









Related Tutorials/Questions & Answers:
a jsp code for creating a text file
a jsp code for creating a text file  Hello,i need jsp code for creating a new text file for each user, when they login in to the website for creating a new data file. So i need a jsp code for following options. when user login
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
Advertisements
How could we get log file as simple text format
How could we get log file as simple text format  Above given javaerrorlog creates the log file in xml code how could we get it in simple text Manmohan
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
Creating a setup file
Creating a setup file  How to create a setup file in tomcat as done in visual studio... could plz tell me as early as possible
creating a file in a directory
creating a file in a directory  hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File
Creating an exe file
Creating an exe file  Hi All, I have developed java application using swing by Net Beans IDE. Now I need to convert my application into exe file... as an exe file. Please anyone suggest me.Thanks in Advance. Thanks, T.Thanga meena
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.  I am reading the file using BufferedReader, then writing the output like this: String
text file
text file  Hello can I modify the program below so that all the numerical data is stored in an external text file,that is the data contained in the array list.Thank you! mport java.util.*; import java.text.*; import
text file
text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should... at the start of the program from a seperate external text file.Thank you! mport
Reading a text file in java
Reading a text file in java  What is the code for Reading a text file... in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
Sorting text file
Sorting text file  Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value... according to begin value. Text File having list like this: 5| 3| can anyone
ModuleNotFoundError: No module named 'log-file'
ModuleNotFoundError: No module named 'log-file'  Hi, My Python...-file' How to remove the ModuleNotFoundError: No module named 'log-file... to install padas library. You can install log-file python with following
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
uploading a text file into a database
uploading a text file into a database  how to upload a text file... { static File file; public static void main(String[] args) throws Exception { JLabel label=new JLabel("Choose File
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
Converting Text Files into Bzip File
Converting Text Files into Bzip File  Hi, I am facing the problem during run the program, when converting text files into Bzip file. Please guide me how do i convert the text file into bzip file in PHP. I will welcome, if anyone
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
Where is servlet log file in net beans?
Where is servlet log file in net beans?  When you use context.log("some string"); then the string get written into the servlet log file. But where is the servlet log file in netbeans? I am using netbeans 6.9. I can't locate
ModuleNotFoundError: No module named 'django-log-file-viewer'
ModuleNotFoundError: No module named 'django-log-file-viewer'  Hi...: No module named 'django-log-file-viewer' How to remove the ModuleNotFoundError: No module named 'django-log-file-viewer' error? Thanks   Hi
Steps to read text file in pyspark
Steps to read text file in pyspark  Hi, I am learning to write program in PySpark. I want to simply read a text file in Pyspark and then try some code. What are the Steps to read text file in pyspark? How much time it takes

Ads