Java 当有人上传文件时,如何从服务器动态捕获文件名
下面是从服务器读取文件的代码。我想动态读取并转换文件,而不是硬编码为不同的文件格式。谁能指导我动态捕获上传的文件名Java 当有人上传文件时,如何从服务器动态捕获文件名,java,file,jsp,upload,Java,File,Jsp,Upload,下面是从服务器读取文件的代码。我想动态读取并转换文件,而不是硬编码为不同的文件格式。谁能指导我动态捕获上传的文件名 try { //creating File instance to reference text file in Java String str1=null; String str2=null; String str3=null; int cnt=0,len1=0,len2=0;
try
{
//creating File instance to reference text file in Java
String str1=null;
String str2=null;
String str3=null;
int cnt=0,len1=0,len2=0;
File text = new File("C:\\Petty Ascii Detail.txt");
//Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(text);
File file = new File("C:\\Test\\Write1.txt");
//if file doesnt exists, then create it
if (!file.exists())
{
file.createNewFile();
}
//Reading each line of file using Scanner class
int lineNumber = 1;
while(scnr.hasNextLine())
{
String line = scnr.nextLine();
cnt=line.length();
for(int i=0;i<3;i++)
{
if (Character.isDigit(line.charAt(i)))
str1=line;
else
str2=line;
}
len1=str1.length();
len2=str2.length();
if(len1!=len2)
{
str3=str1+str2;
FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(str3);
bw.newLine();
System.out.println("Done");
bw.close();
}
lineNumber++;
}
}
catch (IOException e)
{
e.printStackTrace();
}
非常感谢您的建议
谢谢,
巴拉吉人们是如何上传文件的?您是如何接收它们的?请参阅