Creating a log in a text file

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









Related Tutorials/Questions & Answers:
Creating a log in a text file - Applet
Creating a log in a text file  Hey there, I have created an applet... as an application. Therefore i have added it onto a frame. I need to create a text file... time it is run. I have figured of a way of writing the time to a text file using
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
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 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
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 XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
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
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
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
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
creating an .exe file - Java Beginners
creating an .exe file  how to create an .exe file in java? thanks in advance
Creating a File in the directory.
Creating a file using HTML form action In this example, you will learn to make a query form asking to to create a file in PHP. You will have to write... of PHP code in the form.ADS_TO_REPLACE_1 for creating a file in PHP, first
Writing Log Records to a Log File
Writing Log Records to a Log File   ... to a log file. Logger provides different types of level like: warning, info and severe that have log records. Log records are written into a log file
creating a jar file - JSP-Servlet
creating a jar file  Can you give me detail answer 1. i am having a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, Thankyou very much for your... to change the contents of my manifest file. I read somewhere regarding i have to add a line to my manifest file (i.e. Main-Class: mypackage.MyClass
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
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
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, I would like you to please help me, in letting me know, as to how to create JAR file from my JAVA source or class files. And what is this manifest file, and what changes needs to be done
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
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
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
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
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
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
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
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... i want to update the quantity in my text file, if the item i entered matches...=new float[n1]; for(int i=0;i File file ; FileReader fr=null
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
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  
Write Text into File
Write Text into File      ... this example we are initialize string to write into file. We are creating file... to write text into file. At last close output file using close() method.ADS
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
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
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
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
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
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
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
Read Lines from text file
line based on a predefined size... Eg : If the 1st line of the text file... read from the text file and displays the output as desired. Unable to read the rest...Read Lines from text file  Here's a brief desc of what my Java code
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
Creating a JAR file in Java
Creating a JAR file in Java       This section provides you to the creating a jar file.... This program has been used the jar command "jar cf jar-file-name directory
JavaScript write to text file
JavaScript write to text file  ... are going to create a file and write text into it using JavaScript. In the given example... to write the text into the created file, we have used WriteLine() method. This code
Search and return lines of text file
Search and return lines of text file  I wrote the following code, that found lines of txt file with contains certain word, but it returns only the first or the last line! (However, the System.out.println show me all the lines
creating new file with File class - JSP-Interview Questions
creating new file with File class   I have a file uploading concept in my project. For that, while creating a new file is it necessary to give... of FileOutputStream class. If we give the path as from the file uploading location will it work

Ads