How can I get this code to display 20 lines

I need to get this code I have written to display 20 lines at a time, then the 20 using the Enter key.
How would I approach this?
I thought of making a RandomAcessFile object, but that seems like overthinking the problem, and I'm not sure that I could get that to work anyway.
import java.io.*;
public class ReadIt
public static void main(String[] args)
     throws IOException
          System.out.println ("Enter The Desired .java Filename.");
          System.out.println ("Do not add the .java extention.");
          String fname;
          EasyIn type = new EasyIn();
          fname = type.readString();
          String fndotjava = new String(fname + ".java");
          //System.out.println (fndotjava);
          File inFile = new File(fndotjava);
          InputStream istream;
          OutputStream ostream;
          istream = new FileInputStream(inFile);
          ostream = System.out;
          int c;
          try
                 while((c = istream.read()) != -1)
                       ostream.write(c);
          catch(IOException e)
                 System.out.println("Error: " + e.getMessage());      
          finally
                istream.close();
                ostream.close();                 
}Thanks
Brad

Well, a RandomAccessFile together with a counter should work. However, you can also achieve this by buffering the input rather than writing it directly out
java.util.Vector vect = new java.util.Vector();
try{
     while((c = istream.read()) != -1){
         vect.append(c);
catch(IOException e){
     System.out.println("Error: " + e.getMessage());      
finally{
     istream.close();                 
}     with the help of
java.util.Vector.size() and
java.util.Vector.elementAt(int index)
you are able to display only 20 lines at a time, you just need the additional code for reading System.in
public static void prompt(String s){
    System.out.print(s + " ");
    System.out.flush();
  public static String readData ( BufferedReader in)  {
    boolean verfuegbar = true;
    while ( verfuegbar){
      try{
        S = in.readLine();
        if ( S != null)verfuegbar = false ;
      catch (IOException e){System.out.print (e);}
    return S;
  }now it should work with
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
prompt("return for continuing");
int twentscount = 0;
int count = 0;
do{
   while( count < 20 && twentscount+count < vect.size() ){
       outstream.write(vect.elementAt(twentscount + count).toString() );
       count++;
prompt("return");
readData(in);
twentscount += 20;
count = 0;
while(twentscount + count < vect.size());sure, this is code from head, and you can make many changes (e.g. instead of using twentscount use the modulo (%) operator saving one variable (while count % 20 != 0 ).
I'm also not sure if it will definitly run , since i haven't tested it (especialy for index borders).
I hope this will give you enough hints for this possible solution.
Adrian

Similar Messages

  • How can i know how to redeem the code? how can i get this code?

    how can i know how to redeem the code? how can i get this code? please i need you help
    <Email Edited by Host>

    You are trying to create a new Apple ID? You don't have one yet? Is that correct?
    If so, then see this article on how to creat your Apple ID - and make up a password for it. Remember to write it down immediately.
    http://support.apple.com/en-us/HT203993

  • How can I modify this code to display an image in an applet?

    Sorry, I'm almost positive this is absolutely incorrect, but here is what I have so far:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Blackberry extends JApplet implements ActionListener
         Image image;
        public void init()
            //image = getImage(getDocumentBase(), "bluespace.png");
            try { image = ImageIO.read(new File("bluespace.png")); }
              catch (IOException e) { }
        public void paint(Graphics g)
            g.drawImage(image, 0, 0, this);
    }There are no errors given when run as an applet in Eclipse, it just displays a blank window.

    Here's a small example of a JPanel that draws an image:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JPanel;
    public class ShowImageJPanel extends JPanel
      private Image image;
      public ShowImageJPanel(Image image)
        this.image = image;
        Dimension size = new Dimension(
            image.getWidth(this),
            image.getHeight(this));
        setPreferredSize(size);
      @Override
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        if (image != null)
          g.drawImage(image, 0, 0, this);
    }and a JApplet that adds this JPanel into its contentPane:
    import java.awt.Image;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JApplet;
    public class ShowImageApplet extends JApplet
      private static final String IMAGE_PATH = "images/SunSteinSmall.png";
      public void init()
        try
          javax.swing.SwingUtilities.invokeAndWait(new Runnable()
            public void run()
              createGUI();
        catch (Exception e)
          System.err.println("createGUI didn't successfully complete");
      private void createGUI()
        try
          Image image = ImageIO.read(getClass().getResourceAsStream(IMAGE_PATH));
          getContentPane().add(new ShowImageJPanel(image));
        catch (IOException e)
          e.printStackTrace();
    }Here I have a subpackage off of the applet's package called image, and it's filled with Duke images which you can download from here:
    [https://duke.dev.java.net/images/index.html]

  • Hello, how can i get this code working?

    public class TrivialApplication
    public static void main(String args[]){
    class HelloObject
    String greeting="String Test";
    void speak()
    System.out.println(greeting);
    ?

    At a guess I'd say it wouldn't like that because you've defined the class HelloObject inside main.
    Try like so (formatting is done with [ code ] and [ /code ] tags):
    public class TrivialApplication
        private String greeting;
        public static void main(String[] args)
            TrivialApplication ta = new TrivialApplication();
            ta.speak();
        public TrivialApplication()
            greeting = "String Test";
        public void speak()
            System.out.println(greeting);
    }This is a bit of overkill, I certainly could have done it with less code, but it shows the standard format. How you declare variables, and initialise them in the constructor. How to create an object and call methods of the object.
    Or, if you really wanted the HelloObject class...
    public class TrivialApplication
        public static void main(String[] args)
            HelloObject ho = new HelloObject();
            ho.speak();
        class HelloObject()
            private String greeting;
            public HelloObject()
                greeting = "String Test";
            public void speak()
                System.out.println(greeting);
    }HTH,
    Radish21

  • HT2534 What is iTune gift card? How can i get the code from this?

    What's iTune gift card? How can i get the code from this?

    "What's iTune gift card?"
    It is a gift card like any other gift card.  It is a card that contains credit for purchases in the itunes store.
    "How can i get the code from this?"
    Genreally there is a scratch of area under which the code lies.

  • HT5219 How can i get the Apple Thunderolt display to show Windows 7 i run on my system using Paralells desktop..

    How can i get the Apple Thunderolt display to show Windows 7 i run on my system using Paralells desktop..

    You may need to set the slider at the upper-right corner of the Control window to something other than the extreme left-most position:
    Hope this helps.

  • I have an ipod touch 2 and rebuilt my laptop.  Reinstalled ITUNES and can't find my applications on ITunes after login.  I tried to activate Itunes again but it didn't.  How can I get my applications to display on ITUNEs?

    I have an Ipod Touch 2 and rebuilt my laptop.  Reinstalled ITUNES and can't find my applications on ITunes after login.  I tried to activate Itunes again but it didn't.  How can I get my applications to display on ITUNEs?

    It sounds like you essentially have a new computer and unless you restored from a backup your iTunes library would be empty.  You can transfer your iTunes purchases from your iPod to the computer by:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    SInce you changed syncing computers. after you move the stuff you need to restore the iPod to factory defaults and sync the stuff back to your iPod.  If you had the iPod backup file you could restore from backup.
    If you have non-iTunes pruchases you can copy them to your computer by using one of the third-party programs discussed in this previous discussion:
    Best iPod to PC

  • How can I get rid of the display of the last played music-title

    How can I get rid of the display of the last played music-title
    When playing a music-title the name of the title and it's progress is displayed in the box at the top of iTunes, even if the music is already stopped or ended. This display is impeding f.i. when copying music-albums to iPhones and watching the progress. Can anyone tell me please how to make the display of the last played music-title disappear?
    Thank you very much in advance.
    Hans M

    OK, thank you very much, fiend.
    However: Since yesterday afternoon my e-mail-acount is being flooded with 50+ e-mails every few hours which are not at all related to my question. I'm copying the properties of one e-mail as a sample. Could you please organize this flood to stop or tell me what to do?
    Thank you very much!
    Hans M
    Return-Path: <[email protected]>
    Delivered-To: [email protected]
    Received: (qmail 11232 invoked from network); 2 Jan 2014 21:38:42 -0000
    Received: from unknown ([172.18.1.109])
              by mailbox11.aon.at (qmail-ldap-1.03) with QMQP; 2 Jan 2014 21:38:42 -0000
    Delivered-To: CLUSTERHOST smarthub76.res.a1.net [email protected]
    Received: (qmail 9065 invoked from network); 2 Jan 2014 21:38:41 -0000
    X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on
    WARSBL504.highway.telekom.at
    X-Spam-Level:
    Received: from redstreak.apple.com (HELO bz.apple.com) ([17.151.62.54])
              (envelope-sender <[email protected]>)
              by smarthub76.res.a1.net (qmail-ldap-1.03) with RC4-MD5 encrypted SMTP
              for <[email protected]>; 2 Jan 2014 21:38:41 -0000
    X-A1Mail-Track-Id: 1388698720:8973:smarthub76:17.151.62.54:1
    Received: from nwk-jivep-lapp04.corp.apple.com ([17.34.26.3])
    by bz.apple.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0)
    64bit (built Aug 10 2011)) with ESMTP id <[email protected]> for
    [email protected]; Thu, 02 Jan 2014 13:38:40 -0800 (PST)
    Date: Thu, 02 Jan 2014 13:38:39 -0800
    From: Apple Support Communities Updates <[email protected]>
    Reply-to: discussions-replies <[email protected]>
    To: Hans M <[email protected]>
    In-reply-to:
    <2-24330225-3-6714313-1388532858380-2-24354104-3-1039882-1388697859204.jivesbs.ji vemailuser@https://discussions.apple.com/>
    References:
    <2-24330225-3-6714313-1388532858380.jivesbs.jivemailuser@https://discussions.appl e.com/>
    <2-24330225-3-6714313-1388532858380-2-24353958-3-6714313-1388696827692.jivesbs.ji vemailuser@https://discussions.apple.com/>
    <2-24330225-3-6714313-1388532858380-2-24354104-3-1039882-1388697859204.jivesbs.ji vemailuser@https://discussions.apple.com/>
    Subject: [iTunes for Windows] - Re: Cannot follow these instructions
    "Where are my iTunes files located?" [7h40p2-20wvf-ehzw3]
    MIME-version: 1.0
    Content-type: multipart/mixed;
    boundary="----=_Part_577492_1482299802.1388698719437"
    Auto-submitted: yes
    Content-disposition: inline

  • How can i get the code html and css of my form please help me

    how can i get the code html and css of my form

    HI,
    If you like to embed the HTML form in your web page then you will need to obtain the form code from the Distribite/Embed tab. Additional information can be found here: http://forums.adobe.com/docs/DOC-1991
    You will not be able to access/modify the css code or the rest of the form html code.  If you like to view the source of of a HTML page, please use your browser 'view source code' functionality.
    I hope this answer your question,
    Thanks,
    Lucia

  • How can I get iTUNES library to display renamed files and folders (renamed with Windows Explorer)?

    How can I get iTunes library to display the new names and organisation of tracks and albums (ie files and folders) that I have renamed and reorganised (using Windows Explorer) having previously imported them using iTunes?
    (Even when I relocate "lost" tracks in iTunes (using the drop down menu facility to view in Windows explorer), although iTunes will then play the track, and knows where to find it, it refuses to display the track with its correct (new) name, or show it the correct (new) album.  That means I have lots of things called "Untitled" and "Track 01" etc, all of which have actually been renamed, but iTunes does not seem to have the capability to recognise the changes and update its library listing.  Another example - a Tchaikovsky CD with 3 major works in 13 tracks insists on displaying in iTunes as 13 tracks in one album, despite the fact that I have reorganised the tracks into 3 albums - two being Swan Lake and The Nutcracker - and renamed the individual tracks to a more useable format.)

    Thanks for your replies ckuan
    I agree with Tgod that your first solution does not work.  It appears unpredictable whether the old or new file names are listed when you drag the folders into iTunes from Windows Explorer.  The folder structure is completely missing.  I reckon if you have to muck around spending days/weeks/months finding out how to fix links to a secret meta-file (obviously designed by some deep-cover microsoft worm working in the Apple!), then it's pretty obvious that almost any alternate way of doing this would be better.   Bye bye iTunes!!
    Incidentally, I tried several other things that (if the software was designed intuitively) should work, but give disastrous results:
    1) when deleting the library listing in iTunes, it gives you two options - one is to remove the listings to the Recycler.  Be aware that IF you select that option, it removes not only your library listing, but also your ACTUAL MUSIC FILES to the Recycler.  Moreover, it does NOT remove the insidious secret meta-file that is what apparently keeps rewriting old names over your carefully renamed file names, and keeps totally ignoring your carefully designed folder (album) structure.  OK - not a complete disaster, as I realised and went hunting through the chaos in the Recycler to recover all my files.  No thanks to the genius who designed this brilliant feature!
    2) after deleting the library listing in iTunes, I attempted to import just the folders that I wanted.  iTunes refused to allow me to do that, and proceeded to try to import every frigging music file it could find on my whole hard drive, in apparently random fashion into the library.  Whoever thought up that doozy either never ever tried to use or market test it, or has modified their mind rather too many times with artificial substances so their brain is like muesli chop suey.
    3) oh why go on, it's too depressing ...

  • I need Internet Explorer for my MBP.  How can I get this?

    I need Internet Explorer for my MBP.  How can I get this?

    You can't — at least not if you want to run it in the Mac OS. If you have Winidows installed on your Mac, then of course you can run the Windows version of IE, but the Mac version hasn't been updated since June 2003 and is unsupported by Microsoft. It's very insecure, it can't handle a lot of current web sites, and it may not run at all in recent OS X versions. It was lousy in 2003, and it can't have gotten any better while the world was passing it by.
    If there's a web site you want to access that says it requires IE, complain to its webmaster about the benighted design of the site. No responsible web designer codes sites for just one browser any more. Every web site should be tested and should work well with a large variety of browsers — IE, Firefox and Chrome at a bare minimum — and every site owner should insist that their designer(s) adhere to that "best practice."

  • How  can i run this code correctly?

    hello, everybody:
        when  i run the code, i found that it dons't work,so ,i  hope somebody can help me!
        the Ball class is this :
        package {
        import flash.display.Sprite;
        [SWF(width = "550", height = "400")]
        public class Ball extends Sprite {
            private var radius:Number;
            private var color:uint;
            private var vx:Number;
            private var vy:Number;
            public function Ball(radius:Number=40, color:uint=0xff9900,
            vx:Number =0, vy:Number =0) {
                this.radius= radius;
                this.color = color;
                this.vx = vx;
                this.vy = vy;
                init();
            private function init():void {
                graphics.beginFill(color);
                graphics.drawCircle(0,0,radius);
                graphics.endFill();
    and the Chain class code is :
    package {
        import flash.display.Sprite;
        import flash.events.Event;
        [SWF(width = "550", height = "400")]
        public class Chain extends Sprite {
            private var ball0:Ball;
            private var ball1:Ball;
            private var ball2:Ball;
            private var spring:Number = 0.1;
            private var friction:Number = 0.8;
            private var gravity:Number = 5;
            //private var vx:Number =0;
            //private var vy:Number = 0;
            public function Chain() {
                init();
            public function init():void {
                ball0  = new Ball(20);
                addChild(ball0);
                ball1 = new Ball(20);
                addChild(ball1);
                ball2 = new Ball(20);
                addChild(ball2);
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
            private function onEnterFrame(event:Event):void {
                moveBall(ball0, mouseX, mouseY);
                moveBall(ball1, ball0.x, ball0.y);
                moveBall(ball2, ball1.x, ball1.y);
                graphics.clear();
                graphics.lineStyle(1);
                graphics.moveTo(mouseX, mouseY);
                graphics.lineTo(ball0.x, ball0.y);
                graphics.lineTo(ball1.x, ball1.y);
                graphics.lineTo(ball2.x, ball2.y);
            private function moveBall(ball:Ball,
                                      targetX:Number,
                                      targetY:Number):void {
                ball.vx += (targetX - ball.x) * spring;
                ball.vy += (targetY - ball.y) * spring;
                ball.vy += gravity;
                ball.vx *= friction;
                ball.vy *= friction;
                ball.x += vx;
                ball.y += vy;
    thanks every body's help!

    ok, thanks for your reply ! I run this code in the Flex builder 3!and the Ball class and the Chain class are all in the same AS project!
      and i changed the ball.pv property as public in the Ball class, and  the Chain class has no wrong syntactic analysis,but the AS code don't run.so this is the problem.
    2010-04-21
    Fang
    发件人: Ned Murphy <[email protected]>
    发送时间: 2010-04-20 23:01
    主 题: how  can i run this code correctly?
    收件人: fang alvin <[email protected]>
    I don't see that the Ball class has a pv property, or that you even try to access a pv property in the Chain class.  All of the properties in your Ball class are declared as private, so you probably cannot access them directly.  They would need to be public.  Also, I still don't see where you import Ball in the chain class such that it can use it.

  • How can I get this function to fire off last?

    In the following code, there are two buttons on the stage- "button1" and "button2". 
    I want to get the buttons to change frames and THEN have the "playerChange" function fire off.
    Currently, the "playerChange" function fires first. Moving the function  either renders the code inoperable or
    returns error messages.
    function buttonChange (e:MouseEvent)
    {if    
                    (e.target.currentFrame == "frame1" )
             if (e.target==button1) (playerChange)
                     (e.target.gotoAndStop(player.currentFrame + 1)) 
               else{player.gotoAndStop(player.currentFrame)
              if (e.target==button2)  (playerChange) 
                    (e.target.gotoAndStop(player.currentFrame + 1))
              else{player2.gotoAndStop(player2.currentFrame)
    button1.addEventListener(MouseEvent.CLICK,buttonChange );
    button2.addEventListener(MouseEvent.CLICK,buttonChange);
    Note:this is an abridged version of the code. The code I'm actually using uses 20 buttons and about 8 conditionals for each button, so e.target is more convenient than writing a command for each button.

A: How can I get this function to fire off last?

the code is very hard to understand
it's badly formatted
{}'s don't match
you aren't calling a playerChange function
this is my guess at something that might work for you
function buttonChange (e:MouseEvent)
          if(e.target.currentFrame == "frame1" )
                    if (e.target == button1)
                              e.target.gotoAndStop(player.currentFrame + 1);
                              playerChange();
                    else
                              player.gotoAndStop(player.currentFrame);
                              if (e.target == button2)
                                        e.target.gotoAndStop(player.currentFrame + 1);
                                        playerChange();
                              else
                                        player2.gotoAndStop(player2.currentFrame)
button1.addEventListener(MouseEvent.CLICK,buttonChange );
button2.addEventListener(MouseEvent.CLICK, buttonChange);

the code is very hard to understand
it's badly formatted
{}'s don't match
you aren't calling a playerChange function
this is my guess at something that might work for you
function buttonChange (e:MouseEvent)
          if(e.target.currentFrame == "frame1" )
                    if (e.target == button1)
                              e.target.gotoAndStop(player.currentFrame + 1);
                              playerChange();
                    else
                              player.gotoAndStop(player.currentFrame);
                              if (e.target == button2)
                                        e.target.gotoAndStop(player.currentFrame + 1);
                                        playerChange();
                              else
                                        player2.gotoAndStop(player2.currentFrame)
button1.addEventListener(MouseEvent.CLICK,buttonChange );
button2.addEventListener(MouseEvent.CLICK, buttonChange);

  • V5 How can I get the code from an itunes gifcard that got scraped off

    How can I get the code from an itunes gifcard that got scraped off

    Try Here  >  http://support.apple.com/kb/TS1292
    If no joy...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • How can i rewrite this code into java?

    How can i rewrite this code into a java that has a return value?
    this code is written in vb6
    Private Function IsOdd(pintNumberIn) As Boolean
        If (pintNumberIn Mod 2) = 0 Then
            IsOdd = False
        Else
            IsOdd = True
        End If
    End Function   
    Private Sub cmdTryIt_Click()
              Dim intNumIn  As Integer
              Dim blnNumIsOdd     As Boolean
              intNumIn = Val(InputBox("Enter a number:", "IsOdd Test"))
              blnNumIsOdd = IsOdd(intNumIn)
              If blnNumIsOdd Then
           Print "The number that you entered is odd."
        Else
           Print "The number that you entered is not odd."
        End If
    End Sub

    873221 wrote:
    I'm sorry I'am New to Java.Are you new to communication? You don't have to know anything at all about Java to know that "I have an error," doesn't say anything useful.
    I'm just trying to get you to think about what your post actually says, and what others will take from it.
    what does this error mean? what code should i replace and add? thanks for all response
    C:\EvenOdd.java:31: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=true;
    ^
    C:\EvenOdd.java:35: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=false;
    ^
    2 errors
    Telling you "what code to change it to" will not help you at all. You need to learn Java, read the error message, and think about what it says.
    It's telling you exactly what is wrong. At line 31 of EvenOdd.java, you're calling isOdd(), with no arguments, but the isOdd() method requires an int argument. If you stop ant think about it, that should make perfect sense. How can you ask "is it odd?" without specifying what "it" is?
    So what is this all about? Is this homework? You googled for even odd, found a solution in some other language, and now you're just trying to translate it to Java rather than actually learning Java well enough to simply write this trivial code yourself?

  • Maybe you are looking for

    • Business Catalyst Help | Work with pages

      This question was posted in response to the following article: http://helpx.adobe.com/business-catalyst/using/pages.html

    • SMS and Outlook Phone Number Extenstion

      I don't know if this is a N95 or a PC Suite problem. I have used different computers, PC Suite versions and N95 firmware versions to test this. I create a contact in Outlook and add a phone number. For examle: Country: Germany Area Code: 123 Phone Nu

    • Complex Issue

      hai i have 2 infoobjects invoice posting time and invoice approval time. I need to calculate the difference between the invoice posting time and invoice approval time. Suppose , Invoice posting time is at 4:00pm on 03.04.2006 and Invioice approval ti

    • LR3 to CS5 metadata changing

      I start with a DNG in LR3. Take the photo into CS5 using Stack with Original turned on. Make changes and save the file. LR3 tells me the metadata has been changed by another software. Does anybody know why the metadata is being updated? Do I need to

    • TS3694 4005. error iphone 5 restore time

      hello hai i have iphone 5 new os 7 update all iphone error coming difrent error what the solution