• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

File reading

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My text file would be
textfil1.txt


10000|text|1000|java
10001|text|2001|cpp
10002|abc|2003|java
10002|xyz|2003|java
10000|hello|1000|java
10000|hai|2000|cpp



Hear I need to find the duplicate tokens of 1,3,4 tokens in each line.
If any of the line has same tokes of 1,3,4 then will move that line to some other file.
finally I will have only unique 1,3,4 token line in my file.
out put should be

I won't care about 2nd token watever there.

textfil1.txt


10000|text|1000|java
10001|text|2001|cpp
10002|abc|2003|java
10000|hai|2000|cpp



textfil2.txt


10002|xyz|2003|java
10000|hello|1000|java




Please your inputs would be so much help for me
[ July 31, 2008: Message edited by: Chintu sirivennela ]
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give sample input and output for various cases?
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response.

I have given input file 1st , then two output files how the result should be shown.
[ July 31, 2008: Message edited by: Chintu sirivennela ]
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like homework.

Does this have to do with SCJP at all ?
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John Meyers,
yes it looks like that but not home work and not exactly specific to SCJP thing but tt would be solved with the features of java5 may be with Scanner class.

As here many ranchares would have very good understanding on Java 5 features , that why I posted .
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
some one tell me about read the number files at randomly. I have number of jpg files. i want to read these files one by one
 
venus mark
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
someone can check these code.I want to copy the files one folder to another folder.

import java.io.File;

import java.io.*;
public class readfile {

public static void main (String[] arg0)throws Exception{
// you could put your directory here
String pathin = "D:\\Novels";


File filein = new File(pathin);
String[] filelist = filein.list();
int lenin = filelist.length;

File dir=new File("C:\\v");

if (filelist.length == 0) {
System.out.println("empty file in the dirc");

}else{
// define a value for reading the file random
for (int j = 0 ; j < lenin ; j++) {
int index = (int)(Math.random()*lenin);
File newfilein = new File( filelist[index]);
boolean copy= newfilein.renameTo(new File(dir, newfilein.getName()));
System.out.println("name= " + newfilein.getName());
// filelist[index] = filelist[lenin -1];
//lenin --;

}

}


}
}


 
Bras cause cancer. And tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic