使用 <a href> 创建顺序链接的 Java 数组

以文件名作为数组内容创建文件的代码,文件有前一个词的链接,前一个词和后一个词的链接,目前它创建文件但


代码打印


!does 迭代数组只是将数组内容打印为数组指定的位置,它应该将数组写入数组内容迭代为 word 前一个链接与前一个数组内容和下一个链接与下一个数组内容


public class WrHtmlWithLincs 

   {

    public static void main(String args[]) throws IOException 

    { 

    BufferedWriter bw = null;

    FileWriter fw = null;         


    try

    {   

        String word[];

        word = new String[14];

        word[0] = "Software";

        word[1] = "Java";

        word[2] = "Android";

        word[3] = "Code";

        word[4] = "Computer Science";

        word[5] = "Satellite Navigation";

        word[6] = "Communications";

        word[8] = "Calculator";

        word[9] = "JavaScript";

        word[10] = "Stanford";

        word[11] = "Mathematics";            


        for(String Ad : word)

        {            

        try

        {

        fw = new FileWriter("F:\\" + Ad + ".html");            

        bw = new BufferedWriter(fw);

        bw.write("<Table align='center' border='4' color = 'cyan'>");    


        bw.write("<TR>"); 


        bw.write("<TD>"); 

        bw.write("<a href=" + word[y] + ".html>");                                 

        bw.write("Previous"); 

        bw.write("</a>");  

        bw.write("</TD>"); 


        bw.write("<TD>"); 

        bw.write(word[y]); 

        bw.write("</TD>");          


        bw.write("<TD>"); 

        bw.write("<a href=" + word[y] + ".html>");                                 

        bw.write("Next"); 

        bw.write("</a>");

        bw.write("</TD>");             


        bw.write("</TR>");            

        bw.write("<Table>");                        

        }

        catch(IOException d)

        {

        d.printStackTrace();

        }

        finally

        {

        try {

            if (bw != null)

                bw.close();


            if (fw != null)

                fw.close();

        } catch (IOException d) {

            d.printStackTrace();

        }


        }          


        }   

    }                    

    catch(Exception d)

    {

        d.printStackTrace();

    }



四季花海
浏览 169回答 1
1回答

慕丝7291255

这里有一些对你有用的东西。这是我能想到的最接近简单魔术解决方案的方法。将此代码粘贴到您正在工作的班级中的某处:@FunctionalInterfacepublic interface TriConsumer {&nbsp; &nbsp; abstract void consume(Object before, Object current, Object after);}public static final forContext(Object[] arr, TriConsumer consumer){&nbsp; &nbsp; if (arr == null) {&nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; }&nbsp; &nbsp; for (int i = 0; i < arr.length; i++){&nbsp; &nbsp; &nbsp; &nbsp; consumer.consume(i == 0 ? null : arr[i - 1], arr[i], i == arr.length - 1 ? null : arr[i + 1]);&nbsp; &nbsp; }}您可以通过执行以下操作来使用此循环:Word[] wordsArray = //SomethingforContext(wordsArray, (previous, current, next) -> {&nbsp; &nbsp; //Do what you want with the function.&nbsp; &nbsp; System.out.println("The previous word: " + previous);&nbsp; &nbsp; System.out.println("The current word: " + current);&nbsp; &nbsp; System.out.println("The next word: " + next);});编辑:我认为这需要 java 8 或更高版本?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java