Read in data from a file
Hello,
I am EXTREMELY new to java programming. I've read a book on learning java and I have no clue how to read in data from an input (text) file.
I'd like to have the user enter a filename at the keyboard. The file will contain data for two fields separated by a blank. I want to read it into an array of a class of objects. Ex. 1 8
3 8
8 49
The first number should go into array.fld1 and the second number should go in array.fld2.
ex. cout <<< please enter your filename
cin >>filename << endl;
i:=0;
while not eof(filename)
read array.fld1;
read array.fld2;
i++;
Can someone help me with this??
Simple example
try {
BufferedReader in = new BufferedReader(new FileReader("FileName.txt"));
String str;
while ((str = in.readLine()) != null) {
//do whatever whith str
in.close();
} catch (IOException e) {
//Handle Exception...
Similar Messages
-
How to read the data from Excel file and Store in XML file using java
Hi All,
I got a problem with Excel file.
My problem is how to read the data from Excel file and Store in XML file using java excel api.
For getting the data from Excel file what are all the steps i need to follow to get the correct result.
Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
Thanks & Regards,
Sreenu,
[email protected],
india,If you want someone to do your work, please have the courtesy to provide payment.
http://www.rentacoder.com -
Regarding reading the data from the files without using Stremas
hai to all of u...
here i have a problem where i have to read the data from the files without using any streams.
please guide me how to do this one,if possible by giving with an example
Thanks & Regard
M.RamakrishnaSimply put, you can't.
By why do you need to? -
Reading the data from excel file which is in application server.
Hi,
Iam trying to read the data from excel file which is in application server.
I tried using the function module ALSM_EXCEL_TO_INTERNAL_TABLE. But it didn't work.
I tried just reading using open data set and read data set it is giving junk characters.
Please suggest me if you have any solution.
Best Regards,
Brahma ReddyHi Narendra,
Please see the below code I have written
OPEN DATASET pa_sfile for INPUT in text mode ENCODING DEFAULT MESSAGE wf_mess.
CHECK sy-subrc = 0.
DO.
READ DATASET pa_sfile INTO wf_string.
IF sy-subrc <> 0.
EXIT.
else.
split wf_string at wl_# into wf_field1 wf_field2 wa_upload-field3
wa_upload-field4 wa_upload-field5 wa_upload-field6 wa_upload-field7 wa_upload-field8
wa_upload-field9 wa_upload-field10 wa_upload-field11 wa_upload-field12 wa_upload-field13
wa_upload-field14 wa_upload-field15 wa_upload-field16 wa_upload-field17 wa_upload-field18
wa_upload-field19 wa_upload-field20 wa_upload-field21 wa_upload-field22 wa_upload-field23
wa_upload-field24 wa_upload-field25 wa_upload-field26 wa_upload-field27 wa_upload-field28
wa_upload-field29 wa_upload-field30 wa_upload-field31 wa_upload-field32 wa_upload-field33
wa_upload-field34 wa_upload-field35 wa_upload-field36 .
wa_upload-field1 = wf_field1.
wa_upload-field2 = wf_field2.
append wa_upload to int_upload.
clear wa_upload.
ENDIF.
ENDDO.
CLOSE DATASET pa_sfile.
Please note Iam using ECC5.0 and it is not allowing me to declare wl_# as x as in your code.
Also if Iam using text mode I should use extension encoding etc.( Where as not in your case).
Please suggest me any other way.
Thanks for your help,
Brahma Reddy -
How to read the data from a file in another computer with user name and password login
How to read read the data from a file in anohter computer which need to login with user name and password?
duplicate post: http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2061478
duplicate post: http://forums.ni.com/t5/LabVIEW/do-need-to-enter-the-user-name-and-password-when-TCP-ip/m-p/2061612
duplicate post http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2060682 -
Kinect Explorer WPF C# read depth data from the file and conversion to skeleton
Hello,
I am using Kinect sensor to do some research on biometrics. Since it is impossible to find people to collect some samples, I would like to use samples from the TUM - GAID database, where there exist Color View and Depth View (in .raw format) samples. Therefore,
I need to read these samples from the file and do a batch processing, instead of performing real-time collecting of samples (where I can take automatically the Skeleton view using the Kinect SDK). So, I need help on
1. Reading the data from the file (instead of activating the Kinect sensor) and give this data as an input for conversion to a skeleton
2. Read the .raw files
Thank you very much
Kind regardsHiya,
I doubt this forum, C Sharp, will provide much help. You are asking about the Kinects system not C#
language. However, you can try this link; http://kinectforwindows.codeplex.com/
Hope this help. Thanks :) -
How to read the data from excel file and store into the table?
Hi All,
I have table with BLOB datatype contains a excel file. I have to read that data from excel and store into one table with all the fields in excel.
All the excel fields and my table columns are same.
Can you share with me how can acheive this using LOB's?
ThanksHi OraSuirya,
you can try with external tables .
syntax as follows
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
location ('file.csv')
reject limit unlimited;
For this you need to create directory
Directory Creation syntax:
create or replace directory ext_dir as 'D:\oracle\user_dir\ext_dir';
grant read, write on directory ext_dir to <User>;
please paste the excel file in the particular directory .
I hope this will help you.
Please correct me if I am wrong anywhere .
Thanks,
Tippu. -
Hi,
I am tring to read data from a file into my Web Service program. Its a plain text file with item descriptions and price info etc. At the moment I'm trying BufferedReader in = new BufferedReader(...) but I keep getting an exception with Tomcat not being able to locate my file.
Should there be a specific location for files such as this? Or do I need to add a path to a properties or build file? I have tried many different system locations.
I've tried to follow the Sun coffee bean example, but I have found it very complex and would appreciate a clear simple answer.
This is driving me crazy and any help would be much appreciated.
//Daniel.public static void main(String argv[]) {
try {
String filename="absolute path to some file";
BufferedReader in = new BufferedReader(
(Reader)new FileReader(filename)
String line;
while ((line=in.readLine()) != null)
System.out.println(line);
catch (Exception e) {
System.out.println(e.toString()); -
Reading Unicode data from a file...
I am writing an application that needs to read some configuration data from a file. An end user edits the configuration file to provide the configuration data. The Java code reads this file and uses the configuration data supplied by the user.
The user can also save non-ascii characters as part of the configuration data. hence, I do not want to use java properties files. What are the other options available that allow me reading Unicode data into my Java code and will also allow user to save the configuration file as Unicode?Java characters are Unicode characters. Read file data that consists of Unicode characters as Java characters or strings.
You can read the data as primitive char values using the DataInputStream class. The InputStreamReader class can also read Unicode (UTF-16) data.
Data can be written using the OutputStreamWriter class. -
Reading the data from 2 files and writing it into the 3rd file?
Hi,
I am reading datas from 2 files Say,
Example1.txt Example2.txt
Ashok ^data1^data2^data3
Babu ^data1^data2^data3
Chenthil ^data1^data2^data3
Danny ^data1^data2^data3
I want those data's to be written in a 3rd file. Say,
Example3.txt
Ashok^ data1^data2^data3
Babu^ data1^data2^data3
Chenthil^ data1^data2^data3
Danny^ data1^data2^data3
So that i can tokenize it with a delimeter(^) and get the values. Here how to append the datas in this form in Example3.txt. Eventhough u use FileWriter with append "true" as a parameter how they will apend like the Example3.txt file? Please do provide an answer for this..Since this is very urgent to be delivered...Expecting postive response.
Thanx,
JavaCrazyLoverimport java.io.*;
import java.util.*;
public class en
public static void main(String args[]) throws IOException
{int data,data1,offset,offset1;
FileOutputStream fos1=new FileOutputStream("c:/example3.txt");
FileInputStream fis=new FileInputStream("c:/example1.txt");
FileInputStream fis1=new FileInputStream("c:/example2.txt");
while((data=fis.read())!=-1)
fos1.write(data);
while((data=fis1.read())!=-1)
fos1.write(data);
fis.close();
fis1.close();
fos1.close();
}first create those 3 files in c: -
Reading XML data from .pages file
Hi All!
I've been trying to get a script up and running, but frankly I'm lost. The script should read the date, lesson no, and name fields from a .pages file and then use that information to send an e-mail.
What I'm having a problem with is reading the data from the .pages file and I don't know what the best way to do it is because I'm still a novice at this.
So there are two ways I can think of:
1. Read directly from the Pages document when it is open. The problem with this is that it's a Pages template and it contains tables. Perhaps the easiest thing would be just to select certain cells directly from pages, but I have no idea how they're labeled or how to access them so I came up with a second idea. If you happen to know how to do this, I would greatly appreciate it.
2. Pages documents can be unzipped and one of the files is an xml file with a lot of tags and the data I need. I found the following post that talks about how to parse XML via an XSL stylesheet. After going through some tutorials, I got stuck because the xml itself in the Pages file is just a mess to me and I'm confused about which node to choose. In other xml docs you can see a clear, nicely laid out tabbed structure so you can at least figure out the path to the node you want. I stumbled across a nice script for TextWrangler which cleans up XML, but it just barks at the Pages file.
3. On top of that, I will need to use the name field and match that with an Address Book e-mail address. Should I change the template and make it into an address book field?
Thanks in advance,
PaulThe script should read the date, lesson no, and name fields from a .pages file and then use that information to send an e-mail.
Maybe you might want to try the following script:
tell application "Pages"
activate
tell foreground layer of page 1 of front document
select (text box 1 whose vertical position < 0.5)
tell application "System Events"
keystroke "c" using {command down} -- ⌘C
keystroke "a" using {shift down, command down} -- ⇧⌘A
end tell
set theText to the clipboard
end tell
end tell
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab
set theTextFields to text items of theText
set AppleScript's text item delimiters to TID
set {theDate, theLessonNo, theStudent} to {item 2, item 4, item 6} of theTextFields -
I want to read calibration data from a file
I have some calibration data from an experiment. There are 14 channels and the data is arranged in a spreadsheet 14 rows x 4 columns, where each column is a different constant from a best-fit equation of the form y = b1 + b2.x1 + b3.x2 + b4.x1.x2, per channel.
I need to get the data into labview so that I can use it during an experiment. Can anyone recommend the best way to do this? I've tried the 'read from spreadsheet file.vi' but can't get it to work. Any recommendations or example code? Or do you think it is better to use a text file?
Thanks
Dave
Solved!
Go to Solution.They do. From the Help file:
Reads a specified number of lines or rows from a numeric text file beginning at
a specified character ... can use this VI to read a spreadsheet file saved in text format.
Note: The underlining is my emphasis. Still, I understand what you're saying, and as I said, it's been poorly named from the beginning. -
How to read the data from XML file and insert into oracle DB
Hi All,
I have below require ment.
I will receive data in the XML file. then i need to read that data and insert into oracle tables. please let me know how this can be handled.
Many Thanks.Sounds a lot like this question, only with less details.
how to read data from XML variable and insert into table variable
We can only help if you provide us details to help as we cannot see what you are doing and only know what you tell us. Plenty of examples abound on the forums that cover the topics you seek as well. -
Help is needed in my RMI code to read in data from input file
Hi All,
As part of my assignment, I have to develope a client/server application using RMI (not sure why????).
I am new to java and using after going through numerous examples I have come up a class on the server side
to read in the stored data. However during the search I can only display one item (2nd last one) not the entire list
available in the csv file. Any idea how I can fix this? Here is my code..
package rmiexample;
import java.rmi.*;
import java.util.*;
import java.io.*;
public class PropertyServer {
private static final String HOST="localhost";
public static void main (String[] args) throws Exception {
File file = new File("c:\\temp\\property.csv");
try {
// Following line use Scanner class to read data file content line-by-line.
Scanner scanner = new Scanner(file);
int housecount=0;
String line = scanner.nextLine();
while (scanner.hasNextLine()) {
int count=0;
// From the above line of code we got a line from the file
// content. I am spliting the line using '%' as the delimiting
// character. Comma not used as it can be included
// in the address of a property
String[] houseDetail = line.split("%");
String location=houseDetail[0];
String hsePrice=houseDetail[1];
String bedroom=houseDetail[2];
String houseType=houseDetail[3];
String address=houseDetail[4];
String agency=houseDetail[5];
//Converting the price and # of beds to Integer.
double price;
int beds;
beds=Integer.parseInt(bedroom);
price=Integer.parseInt(hsePrice);
PropertyDetails[] propertyList = {
new PropertyDetails(location,beds,houseType,price)};
//I think thisis were I have my problem is....
Vector<PropertyDetails> propDetail = new Vector<PropertyDetails>();
propDetail.add(propertyList[count]);
System.out.println(propertyList[count]);
PropertyImpl temp = new PropertyImpl(propDetail);
String rmiObjectName = "rmi://" + HOST + "/PropertyDetails";
Naming.rebind(rmiObjectName, temp);
count++;
line = scanner.nextLine();
}System.out.println("Binding Complete!!");
catch (FileNotFoundException e) {
e.printStackTrace();
}Take a look at: http://java.sun.com/j2se/1.3/docs/guide/rmi/getstart.doc.html
You need start by declaring an interface that extends Remote. -
How can i read the data from attached file?
using javamail i receiving a mail with attachment
but unable to read the content of the file
Plz help me out
thanks in advanceThe answer is in the JavaMail FAQ.
Maybe you are looking for
-
SAP WM-Stock Placement Strategy "P"
Hi Gurus While using stock palcement strategy "P" "by storage Unit Type" we are dividing bins to section like Stoarge Type Section No of itms 231 A 3 1 2 3 is this code need to append to t
-
JDBC 2.0 method not implemented error using bea jDriver for MS-SQLServer 2000
I'm trying to reconfigure WebLogic Portal 7.0 (Platform 7.0 SP2) to run on MS SQLServer 2000. According to the supported platform docs, the MS JDBC driver is not supported by Portal, hence I'm using the BEA jDriver for SQLServer. I'm now getting the
-
Parsing Problems? ImageIcon and BufferedImage
Hi to everyone Could I ask if I will to send ImageIcon with BufferedImage as its arguement. Then what should I receieve from the server? ImageIcon only or ImageIcon with BufferedImage as its arugement? Any help will be appreciated. Thank You.
-
How to play Ipod in car?
I'm wanting to know how I can play my Ipod in the car? The car doesn't have an auxillary port, nor does it have a cassette tape player and I'd rather have something that I can bring with me on car trips. Does anyone have any suggestions? Thank you in
-
Cost is showing wrongly in CK11N due to Unit of Measurment (UOM)
Dear Experts, Cost is showing wrongly in CK11N Std cost estimates. I maintained 95 INR in Material Master per KG, but 9.5 INR Per KG in CK11N. How to maintain Unit of measurement settings correctly. Regards, KBR.