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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage Return Line Feed

Status
Not open for further replies.

adiMasher

Programmer
Aug 31, 2001
144
US
Alright I'm almost certain there's a better way to do this. But here's what I have so far.

I'm using FileOutputStream to make a log file but when I pass my String to it with a "\n" the new line doesn't appear in the text file.
I was thinking I might need the carriage return character as well. What is the escape character for this?

take a look.
Code:
...
AddtoLog("Copying "+ fso.toString() + " to " + fsoNew.toString() + "\n");
...
   public static void AddtoLog(String logMessage){
	FileOutputStream fos;
	byte[] buff = new byte[1048576];
	int size;

	try{
		fos = new FileOutputStream(logFile, true);
		buff = logMessage.getBytes();
		size = buff.length;
		fos.write(buff,0,size);
	}
	catch(FileNotFoundException fnf){
		System.out.println("File not found" + fnf);
		return;
	}
	catch(SecurityException se){
		System.out.println("Security Exception" +se);
		return;
	}
	catch(IOException e){
		System.out.println("IOException " + e);
	}

    }

thanks,
Martin I don't suffer from insanity.
I enjoy every minute of it.
 
Okay, I'm not quite sure why the current situation doesn't work when everything seems to be in place.

So I just went ahead and used FileWriter

Code:
FileWriter fw;

fw = new FileWriter(logFile);
fw.write(logMessage + "\n");

and this does the trick.

Martin I don't suffer from insanity.
I enjoy every minute of it.
 
Just for the record, "\n\r" will produce CRLF.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top