Home Answers Viewqa Java-Beginners Java programming help with files

 
 


Ruby
Java programming help with files
2 Answer(s)      4 years ago
Posted in : Java Beginners

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 Pages:
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
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
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
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... 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... The largest 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 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
help
(); } } SFDV2103 â?? Java Programming Fall, 2012 Term Project... on the percentage of cheating. SFDV2103 â?? Java Programming Fall, 2012 Term... based on the percentage of cheating. please help me
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
files
.   Please visit the following link: http://www.roseindia.net/tutorial/java/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code: import java.io.*; import java.util.*; class
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 10.4 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook.... The program is a simple file server that makes a collection of files available
Java Programming, Solution to Programming Exercise
some help with using files and command-line arguments, you can find an example... Solution for Programming Exercise 12.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook
help - Java Beginners
, Java : Java is great programming language for the development of enterprise..., and this is very similar to C++. Java Programming Language is simplified to eliminate language features that cause common programming errors. Java source code
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      
java programming problem - JDBC
java programming problem  Hi, Request you to provide a solution... database using java / j2ee. mail id : raichallp@yahoo.co.in... it into the MySQL database. It contains three files :1) ODBCConnection.jsp (reads data
java servlet programming - JDBC
java servlet programming  Hii! frnds My reqiurement is to download multiple files at a time. User selects the files to be downloaded from... displayed in the form of an html table)....after selecting multiple files user
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
FTP Programming in Java tutorials with example code
FTP Programming in Java In this tutorial series of Java programming we are now continuing with the FTP Programming in Java. With the help of these tutorials.../receive files. In this tutorial series we will teach you how to use different Java
java help
java help  How to Open CSV Files in a Microsoft Excel Application Using Java Code with example pgm
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
Files - Java Beginners
BufferedWriter(new FileWriter(file)); } bw.write(str); I hope this will help
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
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
Reading and Writing files - Java Beginners
Reading and Writing files  Hello, please help me to Develop a simple Java application that, when run, Welcomes the users and tells them the name... to investigate writing to files a little (can be also done using Properties
Java Programming: Section 1.7
association with the Web is not Java's only advantage. But many good programming... with other computers on the same network by exchanging data and files... such as files and electronic mail. All communication over the Internet
Java Programming: Chapter 10 Exercises
Programming Exercises For Chapter 10 THIS PAGE CONTAINS programming exercises based on material from Chapter 10 of this on-line Java... are text files. Note that multiple files can be specified, as in "java LineCounts
code for serching files and folders
code for serching files and folders  i want to create a code in java.......plz help me out....   Please visit the following links: http://www.roseindia.net/java/beginners/DirectoryListing.shtml http://www.roseindia.net
Reading Files and Print - Java Beginners
Reading Files and Print  Hey Guys, I'm a beginner to java and I wanna write this program. I wanna create files including information.... There are almost 30 files. When I want to find students whose school is "School
Java Programming: Section 1.4
THERE ARE TWO BASIC ASPECTS of programming: data and instructions. To work.... In Java and most other languages, a variable has a type that indicates what... need to store. Programming languages always have commands for getting data
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
Directories and Files
Java NotesDirectories and Files Put all source files into a directory, one.... It's easy to do. Here are a couple of minor rules. Make sure all classes (.java files... for the source files. The directory name should be lowercase letters, with no blanks
Java Programming: Section 5.6
oriented progrmming in Java. Read it now, or just look through it and refer back... programming languages, such as C++, allow a class to extend two or more... inheritance is not allowed in Java. The designers of Java wanted to keep
Some Notes on Java Programming Environments
Appendix 2: Some Notes on Java Programming Environments ANYONE WHO...-line environments. All programming environments for Java require some text... that I am not an expert on Java programming environments. I am including
Java Programming: Section 7.1
. For images in files, there are two main coding schemes which are used in Java... is there for technical reasons having to do with the funny way Java treats image files... at some additional aspects of graphics in Java. Most of the section deals
Java JAR Files
Java JAR Files      ... with the jar files Result Command Show help info... In computing, a JAR file (or Java ARchive) is used for aggregating many files
Java Programming, Solution to Programming Exercise
Solution for Programming Exercise 11.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... of Section 10.2, will print a list of files in a directory specified by the user
Programming problem - Java Beginners
Programming problem  Good afternoon Ma'am/Sir, Can you help me... it difficult to learn java programming? Based on my survey it seems that java programming is the hardest part of their studies.. I also want to know
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 10.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... of files that are available on the server and display the list on standard
Java Programming: Solution to Programming Exercise
files. Note that multiple files can be specified, as in "java LineCounts file1.txt... Solution for Programming Exercise 10.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Append winword files in java - Java Beginners
Append winword files in java  HI, Im trying to merge 2 winword documents containing text, tables and pictures, resulting doc file should have... 2002...plz help
Java Programming, Chapter 12 Exercises
programming exercises based on material from Chapter 12 of this on-line Java.... Some languages use predicates in generic programming. Java doesn't... help with using files and command-line arguments, you can find an example
help me
help me  MY GLASSFISH SERVER NOT START PROPERLY help me warning shows DPL5404:Specification-Version for the optional package [ GNUJAXP ] in the jarfile [ C:\Program Files\Java\jdk1.7.0_02\jre\lib\ext\gnujaxp.jar
help
help  i need ajava code for compressing files using huffman algorithm (run on netbeans correctly

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.