第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JAVA讀寫文件中的循環(huán)問題

JAVA讀寫文件中的循環(huán)問題

這是一個很酷的昵稱 2017-08-02 15:32:37
代碼如下,想利用Java中一個讀寫文件的類,來實現(xiàn)對文件中每一行進(jìn)行操作創(chuàng)建map,以為利用while循環(huán)可以,沒想到不能循環(huán),得到的結(jié)果只有一個,并不能實現(xiàn)處理每一行,這是為什么呢?求大神指點package testimport java.awt.List;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.util.ArrayList;import java.util.LinkedList;import java.util.Map;import java.util.Vector;import w2v.org.nlp.model.W2Vmodel;/**?*??* @TODO 文件的讀寫?* @得到句子向量?*/public class ReaderAndWriter { String inputpath = ""; String outputpath = ""; @SuppressWarnings("null") public void doit(String inputpath,String outputpath) throws Exception{ BufferedReader input = new BufferedReader(new InputStreamReader( new FileInputStream(new File(inputpath)), "UTF-8")); BufferedWriter output = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputpath), "UTF-8")); String sInput = ""; int count = 0; while ((sInput = input.readLine()) != null) { output.write(sInput); output.newLine(); ? ?int length = 100; int abc = 0; int d=0; int w=0; Map<String,float[]> w2vMap = W2Vmodel.word2Vector(outputpath , length, 0); abc=w2vMap.size();? float[][] save=new float[abc][]; for ( Map.Entry<String,float[]>MyWord2Vector: w2vMap.entrySet()){ String word=MyWord2Vector.getKey(); float[ ] Vector=MyWord2Vector.getValue(); save[d]=Vector; w=Vector.length; d++; } int h=d+1; float ?[]sum=new float[w]; for(int i=0;i<save.length;i++){ for(int j=0;j<save[i].length;j++){ //System.out.print(save[i][j]); sum[j]+=save[i][j]; } } for(int j=0;j<w;j++){ System.out.print(sum[j]/h); } ? System.out.println(); } input.close(); output.flush(); output.close(); } public static void main(String[] args) throws Exception { String inputpath = "C:\\Users\\BG\\Desktop\\result1.txt"; String outputpath = "C:\\Users\\BG\\Desktop\\result2.txt"; ReaderAndWriter n = new ReaderAndWriter(); n.doit( inputpath , ?outputpath ); } }
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 2206 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號