VB:动态创建文件-然后写入文件

时间:2018-07-26 12:49:40

标签: vb.net

VB 中,我想根据当前登录的用户在硬编码文件共享中动态创建一个新的文本文件。

我已经测试了以下代码,该代码的确确实在指定路径中创建了测试文件,但是我想基于 environment.username 来考虑test.txt文件名的动态变化。上课?

Dim objwriter As New System.IO.StreamWriter("\\server\path\test.txt")
objwriter.WriteLine("first line")
objwriter.WriteLine("testing")
objwriter.WriteLine("")
objwriter.Close()

根据我到目前为止获得的结果,我可能必须将变量定义为字符串,然后将其附加到StreamWriter写命令中?

Dim user_name As String = Environment.UserName

现在尝试将两者放在一起..任何帮助将是感激..

1 个答案:

答案 0 :(得分:0)

感谢黑客-达到了目的。

            final OkHttpClient client = new OkHttpClient();
            MediaType mediaType = MediaType.parse("application/json");
            final String credential = Credentials.basic(user, passwd);

            final RequestBody body = RequestBody.create(mediaType, "{\"method\":\"method\",\"params\":[], \"id\": 1, \"chain_name\":\"chain\"}\n");
            final Request request = new Request.Builder()
                    .url(url)
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .addHeader("Cache-Control", "no-cache")
                    .header("Authorization", credential)
                    .build();

            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
                }

                @Override
                public void onResponse(Response response) throws IOException {
                    String resp = response.body().string();
                    try {
                        JSONObject jsonObject = new JSONObject(resp);
                        JSONObject jsonObject1 = jsonObject.getJSONObject("result");
                        Boolean valid = jsonObject1.getBoolean("isvalid");
                        if (valid) {
                            res = "The Address is Valid;
                        }
                        else
                            res = "The Address is not Valid";

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });