Results 1 to 2 of 2
Thread: Write to File
- 12-31-2010, 12:17 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 80
- Rep Power
- 0
Write to File
Hi
I have a little problem
In this code, the programme writes to a file. but the problem is in the red line.
"\n" doesn't work. I need each record of student in one line.
Java Code:import java.io.*; import java.util.*; public class StudentsRecords { public static void main(String[] args){ Scanner scan = new Scanner(System.in); try{ FileWriter fstream = new FileWriter("C://Users//dell//Desktop//G E N E R A L//J A V A//Records.txt"); BufferedWriter out = new BufferedWriter(fstream); int size=0; System.out.print("Enter number of students: "); size = scan.nextInt(); String name=""; int mark=0; for(int i=0; i<size; i++){ System.out.print("Enter Name: "); name = scan.next(); System.out.print("Enter mark: "); mark = scan.nextInt(); [COLOR="Red"]out.write((i+1)+" "+ name + " "+ mark + "\n");[/COLOR] System.out.println(); } out.close(); }catch(Exception e){ System.err.println("Error: " + e.getMessage()); } } }
- 12-31-2010, 01:22 AM #2
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
Similar Threads
-
Write a program that sorts data from a text file and sort them in a file
By danmgz45 in forum New To JavaReplies: 6Last Post: 12-01-2010, 05:31 AM -
write from cmd to a file
By idbirohit in forum New To JavaReplies: 11Last Post: 11-26-2010, 04:23 AM -
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
How to read and write to a file without taking out the comments in the file
By MAGNUM in forum New To JavaReplies: 5Last Post: 02-05-2009, 10:28 AM -
[SOLVED] File Write in File
By Eku in forum New To JavaReplies: 4Last Post: 10-27-2008, 04:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks