本地txt文件 txt的格式如下:
李四 123
张三 345
王五 789
现在要将本地拿到的.txt文件直接读取内容插入数据库中。
现在的疑问:是不是先要把本地文件上传到web工程下面的路径之后,才能读取?
还是不需要路径,可以直接打开.txt文件,然后读取,插入数据库中?
首先,我的txt的格式 有没有什么需要修改的?
巴扎黑2017-04-18 10:57:18
If the web project and the .txt file are running on the same machine, they can be read directly using the absolute path.
If they are passed to the web project, they can be read using the relative path
PHPz2017-04-18 10:57:18
1. You can upload it to the Web project, which means you can get the InputStream. So what should you do first to read the file? Take InputStream.
2. What can you do with the InputStream of txt? You can save the file and read its content. 3. You can read its content. Why not save it directly?
Do you feel that you don’t quite understand the above? This is how I feel when I read the question you asked
Your question is too vague. Please ask more clearly. I don’t know what you are asking
1. By reading a file on the hard disk, format its content and save it into the database ('Now we need to convert the local The obtained .txt file directly reads the content and inserts it into the database. ')2. By reading a file on the hard disk, upload its content to the server, and the server directly reads the file content and stores it into the database. 3. Pass Read a file from the hard disk and upload its content to the server. The server first saves the file, then reads its content, and then saves it to the database
I believe you want 2