Hi..can I ask one question about readLine()?
By having such below codes, I can get it to read first 200 lines out of 500 lines in an output file. - for(int ind=0; ind<200;ind++)
-
{
-
String lineA = "";
-
lineA = inputA.readLine();
-
How to start readLine() at line number 200 until 500 then?
Kindly please advisme how .....Thank you in advance.
37 7561
Hi..can I ask one question about readLine()?
By having such below codes, I can get it to read first 200 lines out of 500 lines in an output file. - for(int ind=0; ind<200;ind++)
-
{
-
String lineA = "";
-
lineA = inputA.readLine();
-
How to start readLine() at line number 200 until 500 then?
Kindly please advisme how .....Thank you in advance.
By just ignoring the lines 1 to 200. Also be sure that there are indeed 500 lines in your buffer/text file! - int numOfLines = 500;
-
-
for(int i = 1; i <= numOfLines && inputA.hasNextLine(); i++) {
-
String line = inputA.nextLine();
-
if(i > 200) {
-
// your code
-
}
-
}
By just ignoring the lines 1 to 200. Also be sure that there are indeed 500 lines in your buffer/text file! - int numOfLines = 500;
-
-
for(int i = 1; i <= numOfLines && inputA.hasNextLine(); i++) {
-
String line = inputA.nextLine();
-
if(i > 200) {
-
// your code
-
}
-
}
Thank you very much. It's working fine.
At first I was using BufferedReader, so I changed it to Scanner...
Eventho I have 2 output files A & B, it works for both files by putting your codes...and that's what I want..tq again.
Thank you very much. It's working fine.
At first I was using BufferedReader, so I changed it to Scanner...
Eventho I have 2 output files A & B, it works for both files by putting your codes...and that's what I want..tq again.
Good to hear that, and you're welcome.
May I ask this one question...Why the execution doesn't stop?
And it stops after executed only a file...I have 40 files need to read and
print out...Thank you in advance. - import java.io.*;
-
-
public class DeleteFile
-
{
-
public static void main(String[] args) throws IOException
-
{
-
for (int m=1; m<=40; m++)
-
{
-
makeOutFile (m);
-
}
-
}
-
-
public static void makeOutFile(int m) throws IOException
-
{
-
PrintWriter printWriter = null;
-
String lineA = ""; //have to skip the next line
-
String lineB = "";
-
-
BufferedReader inputFIRST = new BufferedReader (new FileReader( m + "akbk.txt"));
-
lineA = inputFIRST.readLine();
-
lineB = inputFIRST.readLine();
-
-
while(lineA != null)
-
{
-
printWriter = new PrintWriter( new FileWriter( m + "delAKBK.txt", true));
-
printWriter.println(lineA); //only print one line
-
-
lineA = inputFIRST.readLine();
-
lineB = inputFIRST.readLine();
-
-
printWriter.close();
-
}
-
-
inputFIRST.close();
-
-
}
-
}
May I ask this one question...Why the execution doesn't stop?
And it stops after executed only a file...I have 40 files need to read and
print out...Thank you in advance. - ...
-
-
while(lineA != null)
-
{
-
...
-
}
-
}
If it doesn't stop looping, lineA will probably never become null.
But could you explain what it is you're trying to do? Perhaps I (or someone else) can suggest another way to achieve it: because by only looking at your code, I'm not sure what it is you're trying to do.
Have a look at this little demo: - import java.io.*;
-
-
public class DeleteFile {
-
-
private static File[] getFilesEndingWith(File directory, final String end) {
-
return directory.listFiles(new FileFilter() {
-
public boolean accept(File file) {
-
return file.getName().endsWith(end);
-
}
-
});
-
}
-
-
private static void doSomethingWith(File file) {
-
System.out.println("Do something with: "+file);
-
}
-
-
public static void main(String[] args) throws IOException {
-
-
// Read all files ending with 'akbk.txt' from C:\Temp
-
File[] files = getFilesEndingWith(new File("C:\\Temp"), "akbk.txt");
-
-
// Now do something with those files
-
for(File f : files) {
-
doSomethingWith(f);
-
}
-
}
-
}
Have a look at this little demo: - import java.io.*;
-
-
public class DeleteFile {
-
-
private static File[] getFilesEndingWith(File directory, final String end) {
-
return directory.listFiles(new FileFilter() {
-
public boolean accept(File file) {
-
return file.getName().endsWith(end);
-
}
-
});
-
}
-
-
private static void doSomethingWith(File file) {
-
System.out.println("Do something with: "+file);
-
}
-
-
public static void main(String[] args) throws IOException {
-
-
// Read all files ending with 'akbk.txt' from C:\Temp
-
File[] files = getFilesEndingWith(new File("C:\\Temp"), "akbk.txt");
-
-
// Now do something with those files
-
for(File f : files) {
-
doSomethingWith(f);
-
}
-
}
-
}
Thank you bro for your reply. I tried your methods and happened the same..
So now I knew why it doesn't stop the execution and just produce one file. The file contains too many files (500K++) and imagine have 40 files...can't wait it to be done all files one short. So I have to do it one by one...so muchhhh quicker.
Doesn't matter....
Okay..may I ask one question to you about File?
Actually I am confused how to use RandomAccessFile..or maybe you can help me to explain what does it for? If I have to read/open an image file, let's say JPEG file, so can I use RandomAccessFile instead of InputOutputStream/FileReader?
Kindly please share some info with me...thank you very much
...
Okay..may I ask one question to you about File?
Actually I am confused how to use RandomAccessFile..or maybe you can help me to explain what does it for? If I have to read/open an image file, let's say JPEG file, so can I use RandomAccessFile instead of InputOutputStream/FileReader?
...
Depends what it is you want to do with whose JPEG files. So my question to you is: what are you trying to achieve?
Depends what it is you want to do with whose JPEG files. So my question to you is: what are you trying to achieve?
I just want to open the JPEG file and check how big it is and see the pixels...
I just want to open the JPEG file and check how big it is and see the pixels...
Err, see the pixels? You mean you want to display the image? Then you don't need the java.io package but rather the java.awt package.
Have a look at this tutorial: http://java.sun.com/docs/books/tutor...ges/index.html
Good luck.
Err, see the pixels? You mean you want to display the image? Then you don't need the java.io package but rather the java.awt package.
Have a look at this tutorial: http://java.sun.com/docs/books/tutor...ges/index.html
Good luck.
Nice how a simple "readLine" thread can grow out of hand: before you know it
the image has to come from an RDBMS reading BLOBS over a network
connection and it must be displayed in a browser on a cell phone ;-)
kind regards,
Jos
Nice how a simple "readLine" thread can grow out of hand: before you know it
the image has to come from an RDBMS reading BLOBS over a network
connection and it must be displayed in a browser on a cell phone ;-)
kind regards,
Jos
Yeah, I was thinking the same thing!
; )
you guys cool ! :) :)
I am back to ask readLine() then......Before that thank you for giving me some guidance about reading image file...appreciate it.
Kindly please take a look at my code below: - public static void main(String[] args) throws IOException {
-
for (int m=1; m<=40; m++) {
-
makeOutFile (m);
-
}
-
}
-
-
public static void makeOutFile(int m) throws IOException
-
{
-
String lineA = "";
-
String lineB = "";
-
PrintWriter printWriter;
-
-
try
-
{
-
BufferedReader inputA = new BufferedReader (new FileReader("OutputA" + m + ".txt"));
-
BufferedReader inputB = new BufferedReader (new FileReader("OutputB" + m+ ".txt"));
-
-
lineA = inputA.readLine();
-
lineB = inputB.readLine();
-
-
int testnum = 1;
-
int counterF = 1;
-
-
while(lineA != null && lineB != null)
-
{
-
printWriter = new PrintWriter( new FileWriter( "Result" + m + ".txt", true));
-
-
String a = lineA;
-
String b = lineB;
-
-
if(a == b) //Is this correct way to compare 2 lines that have BigInteger numbers?
-
{
-
printWriter.println(" EQUAL " +testnum);
-
-
}
-
else
-
{
-
printWriter.println(" UNEQUAL " +testnum);
-
-
printWriter.println(counterF);
-
counterF++; //hoping it to count only for unequal
-
}
-
testnum++;
-
-
lineA = inputA.readLine();
-
lineB = inputB.readLine();
-
-
-
printWriter.close();
-
}
-
-
-
inputA.close();
-
inputB.close();
-
-
} catch (IOException e)
-
{
-
System.out.println("There was a problem creating/writing to the temp file");
-
e.printStackTrace();
-
}
-
-
}
1. Something is wrong with my comparison method..it's giving all "UNEQUAL" result. There are equals value too in the both input files..
Here are the sample input files.
InputA:
18088471895755763384595664405566364596733005
18823316190632083835
....//700 lines all together
InputB
18088471895755763384595664405566364596733005
59074062611518823316190632083835
....//700 lines all together
2. I want it to count how many unequal lines then....I know I did wrong there, but just don't know how to make it works....
Kindly please teach me guys...thank you in advance.
Don't compare two Strings for equality using the '==' operaror. Use the member
method equals() instead; e.g. if two distinct Strings a and b both point to two
distinct String values "foo" a == b will return false while a.equals(b) returns true.
kind regards,
Jos
...
if(a == b) //Is this correct way to compare 2 lines that have BigInteger numbers?
...
No. Only primitives can be compared for equality with the '==' operator. When comparing Objects, you should use their equals(...) method: - if(a.equals(b)) {
-
// ...
-
}
Don't compare two Strings for equality using the '==' operaror. Use the member
method equals() instead; e.g. if two distinct Strings a and b both point to two
distinct String values "foo" a == b will return false while a.equals(b) returns true.
kind regards,
Jos
Thank you Jos...I am learning...
btw, why 'foo' is so sinonimn in java?
it's like so many examples about foo...why :)
No. Only primitives can be compared for equality with the '==' operator. When comparing Objects, you should use their equals(...) method: - if(a.equals(b)) {
-
// ...
-
}
Thank you prometheuzz...you guys responded at the same time...cool!.
the equals and counter work fine!
I hope this would be my last question about file's....
Below is my input file (sample):
1 : 30 2
1 : 134 10
2 : 35 2
4 : 30 2
4 : 80 8
..../many more lines
How to delete the same fileno (fileno refers to the first array in line) and take only the first line for the same fileno?
Something like this:
if filenoLine1 == filenoLine2 {
print fileno1
else
print filenoLine1
print filenoLine2
So I will write and get new output file like this:
1 : 30 2
2 : 35 2
4 : 30 2
How's the syntax looks like yeah? - while((lineFRST != null) && (lineSEC != null))
-
{
-
printWriter = new PrintWriter( new FileWriter("OutputFile.txt", true));
-
-
String[] thelineFRST = lineFRST.split(" ");
-
String fileNo1 = thelineFRST[0];
-
-
String[] thelineSEC = lineSEC.split(" ");
-
String fileNo2 = thelineSEC[0];
-
-
if(fileNo1.equals(fileNo2))
-
{
-
printWriter.println(lineFRST);
-
}
-
else
-
{
-
printWriter.println(lineFRST);
-
printWriter.println(lineSEC);
-
}
-
-
printWriter.close();
-
-
lineFRST = in1.readLine();
-
lineSEC = in1.readLine();
-
}
-
-
in1.close();
Problem here is - Read from one file, read 2 lines one short, compare then move them to next two lines...I will miss some equal lines if keep moving two lines one short...again kindly teach me...thank you
Thank you Jos...I am learning...
btw, why 'foo' is so sinonimn in java?
it's like so many examples about foo...why :)
Have a look at this wiki page: http://en.wikipedia.org/wiki/Foo
I hope this would be my last question about file's....
Below is my input file (sample):
1 : 30 2
1 : 134 10
2 : 35 2
4 : 30 2
4 : 80 8
..../many more lines
How to delete the same fileno (fileno refers to the first array in line) and take only the first line for the same fileno?
Something like this:
if filenoLine1 == filenoLine2 {
print fileno1
else
print filenoLine1
print filenoLine2
So I will write and get new output file like this:
1 : 30 2
2 : 35 2
4 : 30 2
How's the syntax looks like yeah? - while((lineFRST != null) && (lineSEC != null))
-
{
-
printWriter = new PrintWriter( new FileWriter("OutputFile.txt", true));
-
-
String[] thelineFRST = lineFRST.split(" ");
-
String fileNo1 = thelineFRST[0];
-
-
String[] thelineSEC = lineSEC.split(" ");
-
String fileNo2 = thelineSEC[0];
-
-
if(fileNo1.equals(fileNo2))
-
{
-
printWriter.println(lineFRST);
-
}
-
else
-
{
-
printWriter.println(lineFRST);
-
printWriter.println(lineSEC);
-
}
-
-
printWriter.close();
-
-
lineFRST = in1.readLine();
-
lineSEC = in1.readLine();
-
}
-
-
in1.close();
Problem here is - Read from one file, read 2 lines one short, compare then move them to next two lines...I will miss some equal lines if keep moving two lines one short...again kindly teach me...thank you
Is this possible to achieve?
Is this possible to achieve?
Of course it is, but how you're trying to do it, is not the best way to do so.
IMO it's better to first read all the lines from your textfile in an array, and the analyse that array afterwards. Don't do these two things at the same time: a method should only be responsible for one thing!
Here's some pseudo code fo you to work on: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static void analyseLines(String[] lines) {
-
LOOP from 'i' <- 0 to 'lines.length'-1, each iteration increase 'i' by 2
-
String 'current' <- the first part of the element at 'lines[i]'
-
String 'next' <- the first part of the element at 'lines[i+1]'
-
IF 'current' is the same as 'next'
-
print 'lines[i]'
-
ELSE
-
print both 'lines[i]' and 'lines[i+1]'
-
END IF
-
END LOOP
-
}
-
-
private static String[] readLines(String fileName) throws IOException {
-
List lines <- new dynamical list
-
// see: http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html
-
-
WHILE 'fileNames' has more lines
-
lines.add(line from 'fileNames')
-
END WHILE
-
return 'lines' as an array of Strings
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile");
-
analyseLines(lines);
-
}
-
}
Good luck.
Of course it is, but how you're trying to do it, is not the best way to do so.
IMO it's better to first read all the lines from your textfile in an array, and the analyse that array afterwards. Don't do these two things at the same time: a method should only be responsible for one thing!
Here's some pseudo code fo you to work on: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static void analyseLines(String[] lines) {
-
LOOP from 'i' <- 0 to 'lines.length'-1, each iteration increase 'i' by 2
-
String 'current' <- the first part of the element at 'lines[i]'
-
String 'next' <- the first part of the element at 'lines[i+1]'
-
IF 'current' is the same as 'next'
-
print 'lines[i]'
-
ELSE
-
print both 'lines[i]' and 'lines[i+1]'
-
END IF
-
END LOOP
-
}
-
-
private static String[] readLines(String fileName) throws IOException {
-
List lines <- new dynamical list
-
// see: http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html
-
-
WHILE 'fileNames' has more lines
-
lines.add(line from 'fileNames')
-
END WHILE
-
return 'lines' as an array of Strings
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile");
-
analyseLines(lines);
-
}
-
}
Good luck.
Could you please take a look at my code? There are 3 errors still: - public class FinalSort
-
{
-
private static void analyseLines(String[] lines, int m)
-
{
-
PrintWriter printWriter = null;
-
BufferedWriter bufferWriter = null;
-
-
printWriter = new PrintWriter(new BufferedWriter(new FileWriter("C:\\result\\" + m +"Final.txt", true))); //To get back 40 output files: eg: 1Final.txt
-
-
for (int i=0; i < lines.length-1; i+=2) {
-
String pos = lines[0];
-
String[] current = pos[i]; //array required but string found
-
String[] next = pos[i+1]; //array required but string found
-
-
if(current.equals(next)) {
-
printWriter.println (lines[i]); }
-
else {
-
printWriter.println (lines[i]);
-
printWriter.println (lines[i+1]);
-
}
-
}
-
}
-
-
-
private static String[] readLines (String fileName) throws IOException
-
{
-
List lines = new ArrayList();
-
-
while (fileName != null)
-
{
-
lines.add (fileName);
-
}
-
return lines; //How to return 'lines' as an array of Strings?
-
}
-
-
-
public static void main(String[] args) throws IOException
-
{
-
for (int m=1; m<=40; m++) // there are 40 files need to be analysed - eg: 1ResultFile.txt
-
{
-
String[] lines = readLines (m + "ResultFile.txt");
-
analyseLines (lines, m);
-
}
-
}
-
-
}
First get your readLines method working. Only then (try to) implement the analyseLines(...) method. -
...
-
private static String[] readLines (String fileName) throws IOException
-
{
-
List lines = new ArrayList();
-
-
while (fileName != null)
-
{
-
lines.add (fileName);
-
}
-
...
-
This is not how you read the lines of a text file. You managed to read lines from a textfile before haven't you? -
...
-
return lines; //How to return 'lines' as an array of Strings?
-
}
-
Have a look at the API docs of the List class I posted earlier. There is a method in there that does just that.
First get your readLines method working. Only then (try to) implement the analyseLines(...) method.
This is not how you read the lines of a text file. You managed to read lines from a textfile before haven't you?
Have a look at the API docs of the List class I posted earlier. There is a method in there that does just that.
Thank you..
Why it's giving error - can't find method toArray(java.util.list)? - private static String[] readLines (String fileName, int m) throws IOException
-
{
-
List lines = new ArrayList();
-
-
String lineFRST = "";
-
String lineSEC = "";
-
-
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
-
-
lineFRST = in1.readLine();
-
lineSEC = in1.readLine();
-
-
while (fileName != null)
-
{
-
lines.add (lineFRST);
-
lines.add(lineSEC);
-
}
-
-
return toArray (lines); //is this correct?
-
}
Thank you..
Why it's giving error - can't find method toArray(java.util.list)?
....
return toArray (lines); //is this correct?
}[/code]
Because there is no method called toArray(...) in your class. You should call that method on your 'lines' reference.
... - private static String[] readLines (String fileName, int m) throws IOException
-
{
-
List lines = new ArrayList();
-
-
String lineFRST = "";
-
String lineSEC = "";
-
-
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
-
-
lineFRST = in1.readLine();
-
lineSEC = in1.readLine();
-
-
while (fileName != null)
-
{
-
lines.add (lineFRST);
-
lines.add(lineSEC);
-
}
-
...
-
}
No: do NOT read two lines at a time. Just read one at a time and add that one line in your List.
Because there is no method called toArray(...) in your class. You should call that method on your 'lines' reference.
No: do NOT read two lines at a time. Just read one at a time and add that one line in your List.
- private static String[] readLines (String fileName, int m) throws IOException
-
{
-
List lines = new ArrayList();
-
-
String lineFRST = "";
-
String lineSEC = "";
-
-
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
-
-
lineFRST = in1.readLine(); //Okay?
-
-
while (fileName != null)
-
{
-
lines.add (lineFRST);
-
}
-
-
return (String[]) lines.toArray(); //Okay?
-
}
Please teach me what's next...TQ
- private static String[] readLines (String fileName, int m) throws IOException
-
{
-
List lines = new ArrayList();
-
-
String lineFRST = "";
-
String lineSEC = "";
-
-
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
-
-
lineFRST = in1.readLine(); //Okay?
-
-
while (fileName != null)
-
{
-
lines.add (lineFRST);
-
}
-
-
return (String[]) lines.toArray(); //Okay?
-
}
Please teach me what's next...TQ
Whether it OK or not can be easily asked to your compiler.
First check if your readLines(...) method works by printing the array your method returns like this: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static String[] readLines(String fileName, int m) throws IOException {
-
List lines = new ArrayList();
-
String lineFRST = "";
-
BufferedReader in1 = new BufferedReader(new FileReader(m+"FileInput.txt"));
-
lineFRST = in1.readLine();
-
while(fileName != null) {
-
lines.add(lineFRST);
-
}
-
return (String[])lines.toArray();
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile", 1);
-
for(int i = 0; i < lines.length; i++) {
-
System.out.println("lines["+i+"] = "+lines[i]);
-
}
-
}
-
}
Whether it OK or not can be easily asked to your compiler.
First check if your readLines(...) method works by printing the array your method returns like this: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static String[] readLines(String fileName, int m) throws IOException {
-
List lines = new ArrayList();
-
String lineFRST = "";
-
BufferedReader in1 = new BufferedReader(new FileReader(m+"FileInput.txt"));
-
lineFRST = in1.readLine();
-
while(fileName != null) {
-
lines.add(lineFRST);
-
}
-
return (String[])lines.toArray();
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile", 1);
-
for(int i = 0; i < lines.length; i++) {
-
System.out.println("lines["+i+"] = "+lines[i]);
-
}
-
}
-
}
Opss...you're right.
Exception in thread " main" java.lang.OutOfMemoryError: Java heap space...
What am I supposed to do then yeah.
Actually total lines of this first file is just 97.
suppose shouldn't be any problem isn't...
Opss...you're right.
Exception in thread " main" java.lang.OutOfMemoryError: Java heap space...
What am I supposed to do then yeah.
This happens because you're in an infinite loop.
This happens because you're in an infinite loop.
I have this to replace the while loop, it's giving me new run time error - Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; can not be cast to [Ljava.lang.String;
have a look and teach me please.. - while (readable)
-
{
-
lineFRST = in1.readLine();
-
if (lineFRST != null)
-
{
-
lines.add(lineFRST);
-
readable = true;
-
} else
-
readable = false;
-
}
-
return (String[]) lines.toArray();
I have this to replace the while loop, it's giving me new run time error - Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; can not be cast to [Ljava.lang.String;
have a look and teach me please.. - while (readable)
-
{
-
lineFRST = in1.readLine();
-
if (lineFRST != null)
-
{
-
lines.add(lineFRST);
-
readable = true;
-
} else
-
readable = false;
-
}
-
return (String[]) lines.toArray();
Try returning it like this: - return lines.toArray(new String[lines.size()]);
Try returning it like this: - return lines.toArray(new String[lines.size()]);
I am really clueless about type error...please.
incompatible types
found : java.lang.Object[]
required: java.lang.String[]
return lines.toArray(new String[lines.size()]);
^ - return lines.toArray(new String[lines.size()]);
-
// return (String[]) lines.toArray();
I am really clueless about type error...please.
incompatible types
found : java.lang.Object[]
required: java.lang.String[]
return lines.toArray(new String[lines.size()]);
^ - return lines.toArray(new String[lines.size()]);
-
// return (String[]) lines.toArray();
That is probably because you didn't declare what type of objects you're storing in your java.util.List (Strings in your case). So, try it like this: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static String[] readLines(String fileName, int m) throws IOException {
-
List<String> lines = new ArrayList<String>();
-
String line;
-
BufferedReader in1 = new BufferedReader(new FileReader(m+fileName));
-
while((line = in1.readLine()) != null) {
-
lines.add(line);
-
}
-
return lines.toArray(new String[lines.size()]);
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile", 1);
-
for(int i = 0; i < lines.length; i++) {
-
System.out.println("lines["+i+"] = "+lines[i]);
-
}
-
}
-
}
That is probably because you didn't declare what type of objects you're storing in your java.util.List (Strings in your case). So, try it like this: - import java.io.*;
-
import java.util.*;
-
-
public class Main {
-
-
private static String[] readLines(String fileName, int m) throws IOException {
-
List<String> lines = new ArrayList<String>();
-
String line;
-
BufferedReader in1 = new BufferedReader(new FileReader(m+fileName));
-
while((line = in1.readLine()) != null) {
-
lines.add(line);
-
}
-
return lines.toArray(new String[lines.size()]);
-
}
-
-
public static void main(String[] args) throws IOException {
-
String[] lines = readLines("/path/to/your/textfile", 1);
-
for(int i = 0; i < lines.length; i++) {
-
System.out.println("lines["+i+"] = "+lines[i]);
-
}
-
}
-
}
Yes, you are really there! It works great. Thank you very much prometheuzz
Just this line makes my program different... - List<String> lines = new ArrayList<String>();
I can't think that complicated....
The next mission is how to compare them....
again please advise me....
Yes, you are really there! It works great. Thank you very much prometheuzz
Just this line makes my program different... - List<String> lines = new ArrayList<String>();
I can't think that complicated....
The next mission is how to compare them....
again please advise me....
I don't know what you mean by "how to compare them", but you don't need to answer that straight away. First try to solve the next problem yourself, and if you don't succeed, post back here. Also post the code you're working on and explain exactly what it is you need help with.
Good luck.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Russell E. Owen |
last post by:
At one time, mixing for x in file and readline was dangerous. For
example:
for line in file:
# read some lines from a file, then break
nextline = readline() # bad
would not do what a naive...
|
by: John C. Worsley |
last post by:
I've got an extremely inscrutable problem here using Perl's
Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and
Term::ReadLine::Gnu 1.14.
The problem is specific to catching INT...
|
by: Jian Qiu |
last post by:
Hi, I tried to install python2.4.2. Unfortunately building 'readline'
extension failed.
Here is what I got: (It is a bit long. If you are impatient, please look
at the end where it reports the...
|
by: David Bear |
last post by:
I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
instance of python from the version packaged with suse.
Now when I start it I get an error:
python
Python 2.4.2 (#4,...
|
by: PointMan |
last post by:
what i know is...
while ((currentStr = sr.ReadLine()) != null)
{
in this area,
can i get next ReadLine Value of currentStr
}
best regard,,
|
by: 7stud |
last post by:
Hi,
1) Does this make any sense:
"""
Thus, the loop:
for line in f:
iterates on each line of the file. Due to buffering issues,
|
by: Sean Davis |
last post by:
I have a large file that I would like to transform and then feed to a
function (psycopg2 copy_from) that expects a file-like object (needs
read and readline methods).
I have a class like so:
...
|
by: Akira Kitada |
last post by:
Hi list,
I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed
to build some of the modules.
"""
Failed to find the necessary bits to build these modules:
_bsddb ...
|
by: Akira Kitada |
last post by:
Hi Marc-Andre,
Thanks for the suggestion.
I opened a ticket for this issue: http://bugs.python.org/issue4204
Now I understand the state of the multiprocessing module,
but it's too bad to see...
|
by: M.-A. Lemburg |
last post by:
On 2008-10-25 20:19, Akira Kitada wrote:
Thanks.
The errors you are getting appear to be related to either some
missing header files or a missing symbol definition to enable
these - looking...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |