java读取txt字符串挨个写入int数组

时间:2022-10-06 05:04:56
 int []num=new int[1001];
FileReader fr = new FileReader("1.txt");
BufferedReader br = new BufferedReader(fr); String str;
StringBuilder sb = new StringBuilder();
while((str=br.readLine())!=null)
{
sb.append(str);
}
String st=sb.toString();
int sum=0,mynum;
for(int i=0;i<st.length();i++)
{
num[i]=Integer.parseInt(st.substring(i,i+1));
}

乍看 很麻烦!