Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java programming help with files
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ruby
Java programming help with files
2 Answer(s)      5 years and 8 months ago
Posted in : Java Beginners



Advertisement
View Answers

May 16, 2009 at 5:29 PM


Hi Friend,

1) With text file:

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

public class ReadEmployeeData{
public static void main(String []args) throws Exception{
Scanner scanner = new Scanner(System.in);
System.out.print("ID: ");
String sen1 = scanner.nextLine();

System.out.print("NAME: ");
String sen2 = scanner.nextLine();

System.out.print("NATIONALITY: ");
String sen3 = scanner.nextLine();

System.out.print("JOB TITLE: ");
String sen4 = scanner.nextLine();

Vector list=new Vector();
list.add(sen1);
list.add(sen2);
list.add(sen3);
list.add(sen4);
System.out.println(list);
String st=list.toString();
String data=st.replaceAll("[\\W]", " ");

BufferedWriter output = null;
File file =null;
if(sen3.equals("American")){
file=new File("AmericanEmployees.txt");
output = new BufferedWriter(new FileWriter(file,true));
output.write(data);
output.newLine();
output.close();
}
else{
file=new File("NonAmericanEmployees.txt");
output = new BufferedWriter(new FileWriter(file,true));
output.write(data);
output.newLine();
output.close();
}
}
}


May 16, 2009 at 5:30 PM


continue............

2) With Random Access File:

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

public class ReadEmployeeData1{
public static void main(String []args) throws Exception{
Scanner scanner = new Scanner(System.in);
System.out.print("ID: ");
String sen1 = scanner.nextLine();

System.out.print("NAME: ");
String sen2 = scanner.nextLine();

System.out.print("NATIONALITY: ");
String sen3 = scanner.nextLine();

System.out.print("JOB TITLE: ");
String sen4 = scanner.nextLine();

Vector list=new Vector();
list.add(sen1);
list.add(sen2);
list.add(sen3);
list.add(sen4);
System.out.println(list);
String st=list.toString();
String data=st.replaceAll("[\\W]", " ");

if(sen3.equals("American")){
RandomAccessFile rand = new RandomAccessFile("American.txt","rw");
rand.writeBytes(data);
rand.close();
}
else{
RandomAccessFile rand = new RandomAccessFile("NonAmerican.txt","rw");
rand.writeBytes(data);
rand.close();
}
}
}
Thanks


Related Tutorials/Questions & Answers:
Java programming help with files - Java Beginners
Java programming help with files  I want a code or the following... then forms two files to store the data; an american employees file and a non-american employees file. The program finally opens the files for output and prints
Java Programming Help
Java Programming Help  Hello ! I m the student of last year and i need your help to complete my java project. I going to make a site like youtube... with controls .. I Just want to use jsp and applet in my project . Please help me
Advertisements
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
Java Programming Code HELP
Java Programming Code HELP  Hi, sir/madam. I am new here and currently developing a program whereby it can read the Java source file... the expert can help me to solve this problem and pull out the attribute name. Can sir
Need help in java programming
Need help in java programming  Hello. Can someone please help me with writig the following programm. Assignment 20% Presentation 10% Mini Test 10% Exam 60% Java program that accepts the following details: student
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program... The largest row index : 2 The largest column index : 2,3 Any help would be greatly
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program... row index : 2 The largest column index : 2,3 Any help would be greatly
Java programming help - Java Beginners
Java programming help  Write a program that asks the user for an integer, and if the input is positive, puts stars on the screen - one star on line... for more information. http://www.roseindia.net/java/ Thanks
Java Programming Need Help ASAP
Java Programming Need Help ASAP  You are required to develop a student menu system that is similar to the bank system covered in class..., their year (you can assume they all start in year 1), their programming mark
Craps Game Java Programming Help
Craps Game Java Programming Help  Craps is a casino game that involves the throwing of a pair of dice. Based on the throw, the thrower either gets... roll. You may wish to print the roll sequence to help you debug. Output
Urgent java programming question.Pls help
Urgent java programming question.Pls help  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list
File handling in Java, Java Files
will help you learning the file handling concepts in Java. The Java... handling in Java. The Java programming language provides I/O System for handling...Java File Handling Tutorials In this tutorial we are providing many different
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text files which has data in the form of intgers consisting of 3 columns and app..3000
Java File Programming
programming examples in java: Reading Big files in Java...Java File Programming articles and example code In this section we will teach you about file programming in your Java applications. Java File Programming
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
hi need help with C++ programming!
hi need help with C++ programming!  how do i : b. Store numbers / characters into the file (output) c. Retrieve numbers / characters from the file (input thanks!   b) #include <iostream> #include <
Programming Help URGENT - JSP-Servlet
Programming Help URGENT  Respected Sir/Madam, I am R.Ragavendran. I am in urgent need of the coding. My requirement is as follows: Beside... TO ROSEINDIA TEAM< IF I GET THIS HELP IN TIME.... Thanks/Regards
java files - Java Beginners
java files  Hi! How to create files (not temporary) when i got exception in my java program. I want to write the complete exception in file...://www.roseindia.net/java/example/java/io/ Thanks
Reading files in Java
suggest for Reading files in Java? Thanks...Reading files in Java  I have to make a program in my project... file in Java. What is the best way to read the file in Java as its big file
Java files - Java Beginners
Java files  i want to get an example on how to develop a Java OO application which reads, analyses, sorts, and displays student project marks.... The input files are structured as follows: ˆ one student record per line ˆ
using java files - Java Beginners
using java files  how i use files in java to store as eg. (information about movies as its name) & when user ask about some movie the movie... in order to understanda   plzzzz people help me
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... a list of JPEG files that my boss gave me, and I was planning on putting them
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
listing files - Java Beginners
listing files  how to list the files and number of files only in a directory?  Hi friend, Code to help in solving the problem...]); System.exit(0); default : System.out.println("Multiple files
java and files - Java Beginners
java and files  hi this is varun working for a software company. i have one doubt that is i have written a program for accessing the xml file from java code,its get executed for that i have used XML Prser. but now
Java programming
common programming errors. Java programming source code files are compiled... support examples related to each Java programming technology that will help... Java programming      
files - Java Beginners
files  Why do we require files to store data?  Hi friend, files to store data, easy to find and access them. Thanks
Java Programming
Java Programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the student√?¬Ę√Ę‚??¬¨√Ę‚??¬Ęs programming mark. Determine how many student get A+ and A for their grade
 

 

 

DMCA.com