Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java and Javaw

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hello...

I have developed a simple java program and part of its functionality is to write to a text file. When i run the program from the windows command prompt using the "Java" command, the program works fine and writes to a text file as expected. However, when i run the program using the "javaw" command the program runs fine apart from the fact it does NOT write to the text file...

Any ideas why this is happening?

Neil
 
file names, directories, or file permissions are probably your problems without seeing your code ...
 
Sedj,

The code i am using is:

import java.io.*;
import java.util.*;
import java.text.*;


public class LogWriter{


private String appName;

/*
*Constructor
*/
public LogWriter(String appName){

this.appName = appName;

}

//write the entry into the log file.
//requires the text that is to be entered and the location
//from where the entry originates.
public void writeToLog(String location, String text){

File logFile = new File(getFileName());
BufferedWriter out;


String currentDateTime = DateFormat.getDateTimeInstance().format(new Date());


try{
//find out if the file exists, if so then just add
//the log entry to it else
if (logFile.exists() ==true){

out = new BufferedWriter(new FileWriter(logFile,true));

} else{

out = new BufferedWriter(new FileWriter(logFile,false));
}


out.write("\n" + currentDateTime + "#:" + location + " " + text + "\r");
out.flush();
out.close();

}catch(Exception e){}


}

/*
* Get the filename to write to.
* Filename will is a rolling number,
* where the number is the day of the month.
*
*/
private String getFileName(){

String currentDay;
String filename;

DateFormat dateText = DateFormat.getDateInstance(DateFormat.SHORT); //create time format

Date now= new Date();

currentDay = dateText.format(now);

currentDay = currentDay.substring(0,2);

filename = appName + currentDay + ".log";


return filename;



}



}

It is just a simple class to log events from a program.

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top