whats up guys, got some more questions. we are starting to learn how to write and read strings to/from txt files. wel thats pretty easy, but how would i retrieve only the first 2 lines of the txt file, for example, if i wanted the first 2 lines, not any other, how would i do it:
12 <--i only need this one and
90 <--this one
12
6
-9
umm, where would i find this method, cause i know sun has a page with all the methods availible to java. so maybe u can elaberate on what u said above or if u have a link to sun's java source page, cause i cant find it. thnks
\
-wes-
ok got the readline to kinda work. im reading from a txt file that contains 10 integers on 10 different lines. i need to read the first 2 lines, and get there some, thenm i need to read the next 2 lines. and add them up and etc..
i got it to read from the file, but its not wokring right, it doesnt read the first line when i tell it to print and it only prints 5 lines? why is htis,
/////////////////////////////////////////////////////////////////////
this is the contenst of the file
public static void main(String[] args)throws Exception{
FileReader inStream = new FileReader("C:\\myText.txt");
BufferedReader buffer = new BufferedReader(inStream);
int numLines=Integer.parseInt(buffer.readLine()); //got thsi from an example, but it only reads the first line. which in the end messes upthe loop below? should i loop this to get a count?
for(int lCount=0;lCount<numLines;lCount++){
String data = buffer.readLine();
System.out.println("de"+ data);
}
System.out.println("number of lines " + numLines );
ok, so dont pay no attention to the above reply. i believe thsi is the way to get everything done, everyhtign is the same as the print out my teacher gave us. the only thing is, how do i line everything up evenly. if u run this in JCreator or whatever u using, u will see how unaligned everything is, can someone help meo ut on how to align everyhting perfectly
also, is this a correct way of writing thios program?
-thnks-
-wes-
import java.io.*;
import javax.swing.JOptionPane;
public class wes{
public static void main(String[] args)throws Exception{
FileReader inStream = new FileReader("C:\\myText.txt");
BufferedReader buffer = new BufferedReader(inStream);
String data;
data = buffer.readLine();
int add = 0;
int diff = 0;
int prod = 0;
yea i did that. as soon as i postedthat i was having trouble, i went back and figured ito ut, thats hwy i wrote dont pay no attention to that reply, i did have a question again with new code if u wanna look at, scrool up, should be right above ur last post,
JCreator has a feature which indents each line of a block of text if you highlight multiple lines and press Tab (Shift+Tab does the opposite).
I did have a related question, but the program suddenly worked as I was typing this reply. For future reference, do you prefer a new thread for a similar problem?
-- Chris
informal JavaScript student of Douglas Crockford
The JavaScript Wiki is under heavy construction; come join us in using and building a more accurate reference!
If it's an unrelated problem, you may wish to make your own thread: you're likely to get more attention if you have asked your own separate queston. Good luck.
>I suck at this game, can you give me some pointers?
Bookmarks